最后请求失败,正确的post怎么写,传json
var xhr = null;
function testXHR() {
if (xhr) {
return;
}
xhr = new plus.net.XMLHttpRequest();
xhr.onreadystatechange = xhrStatechange;
// xhr.open("GET", "http://www.yohaschool.com/dan/dan.ashx?dataA=11");
var data = {
dataA: "11"
};
xhr.open("POST", "http://www.yohaschool.com/dan/dan.ashx");
xhr.responseType = "json";
// xhr.setRequestHeader("dataType", "text");
// xhr.setRequestHeader("Content-Type", "text/json");
//xhr.send(JSON.stringify(data));
// alert(JSON.stringify(data));
xhr.send(data);
}
function xhrStatechange() {
switch (xhr.readyState) {
case 0:
console.log("xhr请求已初始化");
break;
case 1:
console.log("xhr请求已打开");
break;
case 2:
console.log("xhr请求已发送");
break;
case 3:
console.log("xhr请求已响应");
break;
case 4:
if (xhr.status == 200) {
alert("xhr请求成功:" + xhr.responseText);
} else {
console.log("xhr请求失败:" + xhr.readyState);
}
break;
default:
break;
}
}
aaaa (作者)
get对的,就是post不对,用mui的demo里的ajax可以post,但是用XMLHttpRequest就不能post,是不是我写错了
2014-11-18 21:42