要使用AJAX传输JSON数据格式,使用以下步骤:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// 处理服务器的响应
}
};
xhttp.open("POST", "http://example.com/api", true);
xhttp.setRequestHeader("Content-Type", "application/json");
var data = { "name": "John", "age": 30 };
xhttp.send(JSON.stringify(data));
在服务器端,可以使用相应的编程语言(如Java、Python等)来解析接收到的JSON数据。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:ajax怎么返回json数据格式