get方式
let http = new XMLHttpRequest();
http.open("get","http://index.com?id=99");
http.send();
http.onreadystatechange = function(){
if(http.readyState==4 && http.status==201){
console.log(JSON.parse(http.responseText));
}
}
Post方式
let http = new XMLHttpRequest();
http.open("post","http://index.com");
表单格式
//http.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
// http.send(JSON.stringify(`id=99`));
JSON格式
// http.setRequestHeader("Content-Type","application/json")
// http.send(JSON.stringify({
// "id":99
// }))
http.onreadystatechange = function(){
console.log(JSON.parse(http.responseText));
}