//代码演示 var xhr = XHMHttpRequest() //创建 ajax的核心 XHMHttpRequest()对象(实例化) xhr.open() /*使用XHMHttpRequest()实例对象的方法 open(open("method", "url", "async")) method: 请求方式(get、post) url: 请求地址 async: 是否异步(true、false) */ xhr.send() //向服务器发送请求 xhr.onreadystatechange = function () { // onreadystatechange 请求状态改变的触发器 if (readyState == 4) { // 判断 readyState 服务器的请求状态 是否成功 (4代表成功) if (status == 200) { //判断 status 服务器和反馈阶段 是否成功 (200代表成功) console.log(xhr.responsetText)//responsetText 服务器反馈的内容 } } }tatechange 请求状态改变的触发器
原文:https://www.cnblogs.com/x-xwp/p/11326984.html