研究了下Ajax,写了个处理Ajax函数
程序员文章站
2022-06-06 19:38:15
...
/**
* CopyRight (c) Eays Studio
* @author 小林信仁 Date:2007-2-11 QQ:16942926 Email:xihaikun@yahoo.com.cn
*/
var http_request = false;
function send_request(url){//初始化发送请求和处理函数
http_request = false;
//开始创建XMLHttpRequest对象
if(window.XMLHttpRequest) {//Mozailla Navigation
http_request = new XMLHttpRequest();
if(http_request.overrideMimeType){//设置Mime类型
http_request.overrideMimeType("text/html");
}
}else if(window.ActiveXObject){//IE Navigationg
try{
http_request = new ActiveXOjbect("Msxml2.XMLHTTP");
}catch(e){
try{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
if(!http_request){//Exception 不能创建XMLHttpRequest对象
window.alert("不能创建XMLHttpRequest实例");
return false;
}
http_request.open("GET",url,true);
http_request.send(null);
http_request.onreadystatechange = processRequest;//onreadystatechange 是一个事件改变的触发器 等于号后面的是函数没有参数没有刮号,也可以是匿名函数http_request.onreadystatechange = function(){}
//处理返回信息函数
function processRequest(){
if(http_request.readyState == 4 ) {
if(http_request.status == 200){
window.alert(http_request.responseText);//具体操作根据实际修改
}else{
alert("您所请求的页面有异常!!");
}
}
}
}
* CopyRight (c) Eays Studio
* @author 小林信仁 Date:2007-2-11 QQ:16942926 Email:xihaikun@yahoo.com.cn
*/
var http_request = false;
function send_request(url){//初始化发送请求和处理函数
http_request = false;
//开始创建XMLHttpRequest对象
if(window.XMLHttpRequest) {//Mozailla Navigation
http_request = new XMLHttpRequest();
if(http_request.overrideMimeType){//设置Mime类型
http_request.overrideMimeType("text/html");
}
}else if(window.ActiveXObject){//IE Navigationg
try{
http_request = new ActiveXOjbect("Msxml2.XMLHTTP");
}catch(e){
try{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
if(!http_request){//Exception 不能创建XMLHttpRequest对象
window.alert("不能创建XMLHttpRequest实例");
return false;
}
http_request.open("GET",url,true);
http_request.send(null);
http_request.onreadystatechange = processRequest;//onreadystatechange 是一个事件改变的触发器 等于号后面的是函数没有参数没有刮号,也可以是匿名函数http_request.onreadystatechange = function(){}
//处理返回信息函数
function processRequest(){
if(http_request.readyState == 4 ) {
if(http_request.status == 200){
window.alert(http_request.responseText);//具体操作根据实际修改
}else{
alert("您所请求的页面有异常!!");
}
}
}
}
推荐阅读