js 构造get请求
同步
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false 同步
xmlHttp.send( null );
return xmlHttp.responseText;
}
异步
function httpGetAsync(theUrl, callback)//callback 回调方法
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true 异步
xmlHttp.send(null);
}