这可能吗?

xmlHttp.send({
    "test" : "1",
    "test2" : "2",
});

可能与:带有content type的 header :application/json?:
xmlHttp.setRequestHeader('Content-Type', 'application/json')

否则我可以使用:
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')

然后jsont_code JSON对象并在参数中发送它,但是如果可能的话,以这种方式发送它会很酷。

最佳答案

使用jQuery:

$.post("test.php", { json_string:JSON.stringify({name:"John", time:"2pm"}) });

没有jQuery:
var xmlhttp = new XMLHttpRequest();   // new HttpRequest instance
xmlhttp.open("POST", "/json-handler");
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.send(JSON.stringify({name:"John Rambo", time:"2pm"}));

07-24 09:47
查看更多