js中ajax get请求的写法
var xhr=new XMLHttpRequest();
xhr.open('get','请求地址')
xhr.send();
xhr.onreadystatechange=function () {
if (xhr.readyState==4) {
// console.log(xhr.responeText
}
}
js中post请求的写法
var xhr = new XMLHttpRequest();
xhr.open('post',"请求地址",true);
// 如果是post请求 必须加上请求头
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.send("userName="+user.value+'&passWord='+pass.value);
xhr.onreadystatechange =function(){
if (xhr.readyState==4) {
var obj = JSON.parse(xhr.responseText);
console.log(obj.responseCode);
if (obj.responseCode=="0") {
window.location.href = "denglu.html"
}
}
}