XMLHttpRequest
const xhr = new XMLHttpRequest();
xhr.open ( 'GET', './data/test.json', true);
xhr.onreadystatechange = function (){
if( xhr.readyState === 4){
if( xhr.status === 200){
alert( xhr.responseText);
}else {
console.log('其他情况');
}
}
}
xhr.send(null);
const xhr = new XMLHttpRequest();
xhr.open ( 'POST', './login', true);
xhr.onreadystatechange = function (){
if( xhr.readyState === 4){
if( xhr.status === 200){
alert( xhr.responseText);
}else {
console.log('其他情况');
}
}
}
const postData = {
userName = ' ZhangSan ',
password = ' XXX '
}
xhr.send(JSON.stringfy(postData));