7
我試圖將一個數組傳遞給json.stringify,但返回的值是空的。傳遞一個數組到json.stringify
JSON.stringify({ json: data }) // returns `{"json":[]}`
而這裏將是數據的內容:
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;
}
是的,就是這樣。感謝Adam – bflemi3
@ bflemi3 - 當然! –
並將其重命名爲「obj」! – Phrogz