美文网首页
原生ajax封装

原生ajax封装

作者: 194181740bd6 | 来源:发表于2017-05-08 19:18 被阅读0次

    /**

    * Created by Computer on 2016/6/20.

    */

    function createHTTPRequest(){

    try{

    return new window.XMLHttpRequest();

    }catch (e){

    try{

    return new ActiveXObject("MSXML2.XMLHTTP.6.0");

    }catch (e){

    try{

    return new ActiveXObject("MSXML2.XMLHTTP.3.0");

    }catch (e){

    try{

    return new ActiveXObject("MSXML2.XMLHTTP");

    }catch (e){

    throw Error("this browser is not supported");

    return;

    }

    }

    }

    }

    }

    function ajaxRequest(_method,_url,_async,_parameter,_function){

    var _ajax=createHTTPRequest();

    if(_ajax){

    _ajax.onreadystatechange=function(){

    if(_ajax.readyState==4 && _ajax.status==200){

    _function(_ajax.responseText);

    }

    }

    _ajax.open(_method,_url,_async);

    _ajax.setRequestHeader("Content-Type","Application/x-www-form-urlencoded;charset=utf-8");

    _ajax.send(_parameter);

    }

    }

    相关文章

      网友评论

          本文标题:原生ajax封装

          本文链接:https://www.haomeiwen.com/subject/abxvnttx.html