1. Example of an ajax object
var ajax = new XMLHttpRequest()
2. The ajax object opens the interface ajax.open (request method, interface address, asynchronous or not) Asynchronous: multiple threads run simultaneously (true) Synchronous: single thread runs sequentially (false)
ajax.open('get','http://localhost:3000/list','true')
3.ajax object sends request
ajax.send()
4. Monitor whether the request is successful
ajax.onreadystatechange = function(){
if(ajax.readyState==4){
if(ajax.status==200){
//相应ajax.respose 默认json字符串 转化为json
//json字符串转换为json对象 var res = JSON.parse(ajax.response)
//json对象转换为json字符串 var res = JSON.stringify(ajax.response)
var res = JSON.parse(ajax.response)
console.log(res)
console.log(ajax.response)
}
}
}