跨浏览器 创建xmlhttprequest 对象 以及和服务器交互的全过程
2016-10-18 23:03
405 查看
//创建xhr对象
function creat(){
var xhr;
try{
xhr = new XMLHttpRequest();
}catch(e){
var versions =["MSXML2.XMLHttp.6.0",
"MSXML2.XMLHttp.3.0",
"MSXML2.XMLHttp"];
for(var i=0;i<versions.length;i++){
try{
xhr = new ActiveXObject(versions[i]);
}catch(e){
continue;
}
}
}
return xhr;
}
var xhr = creat();
xhr .readystatechange = function(){if(xhr.readystate==4){
if(xhr.status>=200&&xhr.status<300||xhr.status==304){
//dosomething
}
}
}
xhr.open("method",url,true);
xhr.send(null);
相关文章推荐
- 创建XMLHttpRequest对象并向服务器发送请求的方法
- 使用ajax访问服务器时---创建XMLHttpRequest对象
- ajax的概述和XMLHTTPRequest对象的创建过程
- AJAX笔记一创建XMLHttpRequest对象,以及XMLHttpRequest对象的常用属性
- Java乔晓松-ajax的概述和XMLHTTPRequest对象的创建过程
- Ajax中XMLHttpRequest对象的创建和servlet中数据的交互
- 创建新的 XMLHttpRequest 对象
- 创建XMLHttpRequest对象的一个实例
- ajax通用创建XMLHttpRequest对象
- 10XMLHttpRequest对象的创建,及发送和接收数据
- 使用xmlHttpRequest对象完成异步交互时,遇到的问题
- 使用xmlhttprequest对象来进行AJAX的异步数据交互
- 创建XMLHttpRequest对象的一个实例
- AJAX 创建 XMLHttpRequest对象
- 创建 XMLHttpRequest 对象
- 创建xmlHttpRequest对象在FireFox中支持Ajax
- 创建具有错误处理能力及多种浏览器通用的 XMLHttpRequest对象
- 一个创建XMLHttpRequest对象的js文件(适用asp,php,jsp,asp.net等)
- 以支持多种浏览器的方式创建 XMLHttpRequest 对象
- XMLHttpRequest对象创建数据请求处理