美文网首页
2018-03-15

2018-03-15

作者: 逮呆 | 来源:发表于2018-03-20 13:21 被阅读0次

    AJAX基本框架

    function Ajax(url,funSucc,funFaild){

    var request = getAjax();

    if(request){

    request.open("GET",url,true);

    //发送请求

    request.send(null);

    //接受返回

    request.onreadystatechange=function(){

    if(request.readyState==4){

    if(request.status==200)

        funSucc(request.responseText);

    else{

    if(funFaild)

    funFaild(request.status,request.responseText);

    }

    }

    };

    }else{

    alert("Sorry,your browser doesn't support XMLHttpRequest");

    }

    }

    function getAjax(){

    if(typeof window.XMLHttpRequest=="undefined")

    XMLHttpRequest=function(){

    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){}

    return false;

    }

    return new XMLHttpRequest();

    }

    相关文章

      网友评论

          本文标题:2018-03-15

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