美文网首页
ajax2.0封装,不兼容适合移动端

ajax2.0封装,不兼容适合移动端

作者: 前端小虾 | 来源:发表于2016-11-29 22:54 被阅读0次
<script>
    var oAjax=new XMLHttpRequest();
    oAjax.open('GET','http://demo.zhinengshe.com/zl/ky3.php?a=1&b=3&t='+Math.random(),true);
    oAjax.send();
    //ajax加载完
    oAjax.onload=function(){
        if(oAjax.readyState==4){
            if(oAjax.status>=200&&oAjax.status<300 || oAjax.status==304){
            alert(oAjax.responseText);
                
            }else{
                alert(oAjax.status);
            }
        }
    };
    oAjax.timeout=2000;//毫秒
    oAjax.ontimeout=function(){
        alert('超时了!');
    };
    //发生错误执行的
    oAjax.onerror=function(){
        alert('发生错误了!')
    };
    //上传进度
    oAjax.onprogress=function(ev){
        console.log(ev.loaded/ev.total);
    };
</script>

以后有可能替代传统ajsx哦!!

相关文章

网友评论

      本文标题:ajax2.0封装,不兼容适合移动端

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