我正在使用此函数将 json 发送到 php 页面:
function update_records(data) {
data = data;
$.ajax({
type: 'POST',
cache: false,
timeout: 2000,
contentType: 'application/json',
url: 'update.php',
data: data, //'data='+data+'&aid=0',
success: function() {
success_message('success');
},
error: function(){
failure_message('failure');
}
});
在 firebug 中我可以看到发布的数据:
[{
"postid": 66,
"values": [
"field_key=a",
"oldvalue=b",
"newvalue=c dad"
]
}]
在我的 php 页面上如何$_REQUEST
对象?还是我做错了?
最佳答案
我实际上确实在我的 js 上使用此代码解决了这个问题
这就是我收集数据的方式 我已经创建了对象
jsonObj={"postid":postid,"value":value};
var jsonString=JSON.stringify(jsonObj);
现在我使用ajax发送对象
$.ajax({
type: 'POST',
url: siteurl+'/wp-content/themes/crm/modules/update_lead.php',
dataType : 'json',
data: {action:actionType,data:data},
});
这位于目标 PHP 文件 (/wp-content/themes/crm/modules/update_lead.php)
$json=json_decode(stripslashes($_POST['data']), true);
希望这有帮助......
关于PHP - 在 PHP 中检索 ajax 发布的 json 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9326566/