We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// 创建XMLHttpRequest对象 function xhr(){ var xhr; try { xhr = new XMLHttpRequest(); }catch(e){ try{ xhr = new ActiceXObject('Msxml2.XMLHTTP'); }catch(e){ try{ xhr = new ActiveXObject('Microsoft.XMLHTTP'); }catch(e){ alert('不支持 ajax'); return fasle; } } } return xhr; } /** 发送Ajax请求 * url:请求地址 * methodType: GET,POST,HEAD 请求方式 * sycn: true,false 同步或异步 * callback 回调 * obj 回调中要处理的对象 */ function ajaxRequest(url,methodType,sycn,callback,obj){ var xhr = xhr(); xhr.onreadystatechange = function(){ if(xhr.readyState == 4){ if(xhr.status == 200){ obj.result = xhr.responseText; console.log(xhr); callback(obj); } } } xhr.open(methodType,url,sycn); xhr.send(null); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
从 Ajax 入手理解 XMLHttpRequest 对象
先写一个完整的Ajax请求
XMLHttpRequest的属性
当readyState属性发生变化时会调用
0:未打开,open()方法未调用
1:未发送,send()方法未调用
2:以获取响应头,send()方法已调用,响应头响应状态已经返回
3:正在下载响应体,responseText中已获取部分数据
4:请求完成,整个请求已经完毕
"": 返回字符串(默认)
"arraybuffer": 返回ArrayBuffer
"blob": Blob
"document": Document
"json": JSON字符串
"text": 字符串
本次响应为文本
XMLHttpRequest的方法
The text was updated successfully, but these errors were encountered: