ajax异步如何返回responseText

原文地址:http://cache.baiducontent.com/c?m=9d78d513d9d437a94f9993697b15c012124381132ba6da020cd7843894732a40506793f1787c0705a39f3a2143b8482cfdf04165367360e0da8ad5169cec85295fce707e360b873105a31eb8ba4032c050872aecb869e0ad804284d8d8c4de2444bc57120a87e4cc1a5e1b9029b65626e2d58455501a55aded4733a81c2075882337ed1ae4a32f6e078af4&p=8b2a9702909706ff57ed977b5b648c&newp=82769a479e8903ff57ed977b7f64c1231610db2151dcd55d3596&user=baidu&fm=sc&query=%D4%F5%D1%F9%C8%A1%B5%C3xmlHttp%2EresponseText%B5%C4%B7%B5%BB%D8%D6%B5&qid=e3a54b05000055ba&p1=31




function httpGET(url,sync,fun){
var xhr = window.XMLHttpRequest? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        if(typeof sync === 'function') {
            fun = sync;sync =true;
        }else if(typeof sync === 'undefined'){
             sync =true;
        }
        xhr.onreadystatechange=function(){
          if(xhr.readyState==4 && xhr.status==200){
                fun.call(this,xhr.responseText);
          }
        }
        xhr.open("GET",url,sync);
        xhr.send();
    }
    
    //调用方法
    httpGET("/index.php",function(data){
        alert(data);
    });


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值