如何通过原生的ajax去提交json格式的数据呢?
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if(xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
}
}
xhr.open('POST', 'http://test.csiem.baidu.com/api/v1/userProfile/lbs', true);
xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8'); //设置HTTP header字段值
var postData = {domain: "xywy.com"}; //需要发送的数据
xhr.send(postData);
但是最后提交的时候显示的post的数据为[object object];
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
请放弃ajax,用fetch,新的原生接口,比ajax更方便使用
转换成键值对才行;当然也可以直接吧json转成字符串提交,到服务器时再编码成数组就行