/*异步传输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);
}
原文:http://www.cnblogs.com/wwqianduan/p/3601125.html