zoukankan      html  css  js  c++  java
  • 完美兼容IE、FF、Opera的Ajax类支持get、post、自定义回调函数

    function Ajax(){  
    this.httpXML=false;  
    this.init();  
    }  
    Ajax.prototype.init=function(){  
    if(window.XMLHttpRequest){  
    this.httpXML=new XMLHttpRequest();   
    if (this.httpXML.overrideMimeType){  
    this.httpXML.overrideMimeType("text/xml");   
    }  
    }else if(window.ActiveXObject){  
    try{this.httpXML = new ActiveXObject("Msxml2.XMLHTTP");}catch (e){   
    try{this.httpXML = new ActiveXObject("Microsoft.XMLHTTP");}catch (e){}   
    }  
    }  
    if(!this.httpXML){  
    window.alert("can't create XMLHttpRequest object");  
    return null;  
    }  
    }  
    Ajax.prototype.send=function(_method,_url,_data,_callback){  
    this.httpXML.onreadystatechange=function(){  
    if(this.readyState==4&&this.status==200){  
    _callback.call(this,this.responseText);  
    }  
    }      
    if (_method.toLowerCase() == "get"){   
    this.httpXML.open(_method, _url, true);   
    this.httpXML.send(null);   
    }else if (_method.toLowerCase() == "post"){   
    this.httpXML.open(_method, _url, true);   
    this.httpXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");   
    this.httpXML.send(_data);   
    }      
    }
    //===========================================
    function getResult(data){
    alert(data);
    }
    new Ajax().send('post','url','a=1&b=2',getResult);
  • 相关阅读:
    unity3d工具栏介绍
    初识unity3d
    js模拟表单提交
    配置Appium环境
    html单选框 bootstrap模态框里面的单选框 和jq取值
    解决输入框总被浏览器记住的记录遮挡住的问题
    U盘
    python 字典列表/列表套字典 去重重复的字典数据
    ajax把数据return出去
    js把列表转换成字符串
  • 原文地址:https://www.cnblogs.com/top5/p/1988081.html
Copyright © 2011-2022 走看看