我对如何从jquery / ajax / json rpc调用检索数据服务器端感到头疼!
这是客户端:
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: 'http://wine-trip.net/php/ajax/setVinImage.php',
data: JSON.stringify({jsonrpc:'2.0',method:'add',params:[{'vigneronID':'14818','action':'deleteImage','vinID':'13','vinImageType':'Bouteille'}],id:"jsonrpc"}),
dataType:"json",
success:function(data){
if (typeof (data.error.message) === 'undefined') {
// Everything was OK
}
else{
alert(data.error.message);
}
},
error: function(req) {
alert("Networking problem");
}
});
这是服务器端的开头:
// HTTP headers for no cache etc
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
error_log("POST ".$_POST['vigneronID'], 0);
error_log("REQUEST ".$_REQUEST['vigneronID'], 0);
我从服务器显示警报但是无法访问我通过params的数据(错误的语法?)得到答案。
我可以进行正常的ajax调用,但由于我使用的是plupload库(与json rpc一起使用),我想弄清楚为什么我不能使用这种方法!
我尝试过使用或不使用contentType但似乎没有改变任何内容......
答案 0 :(得分:0)
我猜测error_log会发出一些字符串?它有助于使用json_encode http://php.net/manual/en/function.json-encode.php。我还建议使用firefox等firebug等开发人员工具,你可以看到你的服务器发送了什么