jquery ajax帖子数组返回空

问题描述 投票:0回答:2

发布具有以下格式的JSON.stringified数组:

[{"AccountNumber":1630,"AccountName":"text1","Balance":83,"AccountType":6,"AccountTypeDescription":"text2"},{"AccountNumber":1930,"AccountName":"text3","Balance":1444492.39,"AccountType":9,"AccountTypeDescription":"text4"}]

在php端,它返回一个空数组。缺少什么?

JQuery编码:

$.ajax({
url: 'url.php',
type: 'post',
contentType: 'application/json',
data: JSON.stringify(resp.responseJSON.Data),
success: function (data2) {
console.log(data2);
},
});

Php:

print_r($_POST);
php jquery post
2个回答
0
投票

我认为这行有undefined错误:

data: JSON.stringify(resp.responseJSON.Data)

如果您的数组变量名称是resp

var resp=[{"AccountNumber":1630,"AccountName":"text1","Balance":83,"AccountType":6,"AccountTypeDescription":"text2"},{"AccountNumber":1930,"AccountName":"text3","Balance":1444492.39,"AccountType":9,"AccountTypeDescription":"text4"}]

然后尝试:

$.ajax({
url: 'url.php',
type: 'post',
contentType: 'application/json',
data: JSON.stringify(resp),
success: function (data2) {
console.log(data2);
}
});

-1
投票

删除数据部分中的JSON.stringify并将响应放入数组中。喜欢,var urdata = [];urdata.push(resp.responseJSON.Data);

在Ajax通话中:数据:urdata

© www.soinside.com 2019 - 2024. All rights reserved.