首页 > 其他 > 详细

异步传输

时间:2014-03-15 07:25:32      阅读:428      评论:0      收藏:0      [点我收藏+]

/*异步传输json strData的数据如:name=value&name1=value1&name2=value2*/
function loadJson(method, url, strData, f, async) {
    if (typeof (async) == "undefined") async = true;
    var xr = new XMLHttpRequest();
    xr.onreadystatechange = function(){
        if(this.readyState  == 4){
            if(this.status == 200 &&this.responseText != ""){
                if(typeof(f) === ‘function‘)
                       f(eval(‘(‘+this.responseText+‘)‘));
            } else {
                if (typeof (f) === ‘function‘)
                    f(null);
            }
        }
    }
    xr.open(method, url, async);
    if(method.toLowerCase() == ‘post‘)
        xr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xr.send(strData);
}

异步传输,布布扣,bubuko.com

异步传输

原文:http://www.cnblogs.com/wwqianduan/p/3601125.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!