Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
50
rated 0 times [  57] [ 7]  / answers: 1 / hits: 18591  / 13 Years ago, fri, january 20, 2012, 12:00:00

I'm trying to pass an array to json.stringify but the returned value is coming back empty.



JSON.stringify({ json: data }) // returns `{json:[]}`


And here would be the contents of data:



data[from] = [email protected]
data[to] = [email protected]
data[message] = testmessage


jquery:



function SubmitUserInformation($group) {
var data = {};
data = ArrayPush($group);
$.ajax({
type: POST,
url: http://www.mlaglobal.com/components/handlers/FormRequestHandler.aspx/EmailFormRequestHandler,
data: JSON.stringify({ json: data }),
dataType: 'json',
contentType: application/json; charset=utf-8,
cache: false,
success: function (msg) {
if (msg) {
$('emailForm-content').hide();
$('emailForm-thankyou').show();
}
},
error: function (msg) {
form.data(validator).invalidate(msg);
}
});
}

function ArrayPush($group) {
var arr = new Array();
$group.find('input[type=text],textarea').each(function () {
arr[$(this).attr('id')] = $(this).val();
});
return arr;
}

More From » jquery

 Answers
13
data = ArrayPush($group);


Is re-assigning data to be an array, so all your expando properties are not being stringified.



Inside your ArrayPush method, change



var arr = new Array();


to



var obj = { };

[#87893] Thursday, January 19, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaquelineh

Total Points: 360
Total Questions: 105
Total Answers: 114

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;