如何使用jquery提交将json字符串发送到php文件?

*嗨,我在Jquery中使用JSON非常新。 我有一个html表单,使用json数据和javascript。 Json字符串保存结果。 现在我的问题是如何将此字符串发送到php文件。 我使用ajax函数提交表单* 这是我拥有的json字符串

var jsonstr = JSON.stringify(result); $.ajax({ type:"POST", url: "ajax.php", headers: { 'Content-Type': 'application/json', success: function(){ alert('Test results submitted!');; 

指定datadataType选项:

 var jsonstr = JSON.stringify(result); $.ajax({ type:"POST", url: "ajax.php", data:'json=' + jsonstr, dataType:'json', success: function(){ alert('Test results submitted!'); } }); 

从php,您可以使用以下命令获取json字符串:

 $_POST['json'];