ajax收藏

/*异步传输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+')'));
            }
        }
    }
    xr.open(method, url, async);
        if(method.toLowerCase() == 'post')
            xr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xr.send(strData);
}

posted @ 2013-12-27 16:15  王坑坑在翻滚中  阅读(201)  评论(0编辑  收藏  举报