// const data = JSON.stringify({
// "Context":{
// "argv":{
// "section":"运单管理"
// ,"key":"机器人"
// }
// }
// });
// console.log(data);
// const xhr = new XMLHttpRequest();
// xhr.withCredentials = true;
// xhr.addEventListener("readystatechange", function () {
// if (this.readyState === this.DONE) {
// console.log(this.responseText);
// }
// });
// xhr.open("POST", "");
// xhr.setRequestHeader("Content-Type", "application/json");
// xhr.setRequestHeader("AirScript-Token", "");
// retJson = xhr.send(data);
// console.log(retJson.json());
var xhr = new XMLHttpRequest();//第一步:新建对象
xhr.open('POST', 'https://www.baidu.com', true); // 建立连接
xhr.setRequestHeader("Content-type","application/json");//设置请求头 注:post方式必须设置请求头(在建立连接后设置请求头)
var obj = { name: 'zhansgan', age: 18 };
xhr.send(JSON.stringify(obj));//发送请求 将json写入send中
/**
* 获取数据后的处理程序
*/
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);
// 代码逻辑
}
};