jquery将json数据发布到PHP文件

我有一个click事件,我在其中撰写json数据 ,然后我想将其POST到PHP文件进行处理 。 但出了点问题。 我的PHP文件现在简化了,如下所示:

 

POST的代码如下所示:

 // myarray is: var myarray = new Array(); // and it gets populated above this code var strObj = JSON.stringify(myarray); alert(strObj); // so far I get the alert containing valid JSON text $.ajax ({ type:"POST", url:"proces.php", contentType: "application/json", dataType: "json", async: false, data: strObj, success: function(){ alert("success")}, error: function(){ alert("error")} }); 

因此,当我单击按钮时,我收到包含JSON字符串的警报(看起来很好),然后我收到警告说“错误”,当我检查控制台以查看proces.php的响应时,我看到的是:

 array(0) { } 

我究竟做错了什么? 我该怎么做才能做到对?

这对我有用:

 $.ajax ({ type:"POST", url:"proces.php", dataType: "json", async: false, data: {tmp: strObj}, success: function(){ alert("success")}, error: function(){ alert("error")} }); 

我自己得到了答案。 似乎可以做到这一点:

 $.post("proces.php", {json: JSON.stringify(myarray)}, function(data){alert(data);}); 

我的意思是,我没有得到警报(数据); (可能是因为我没有从php文件返回JSON)但是在PHP中我现在可以看到json数据。