var xmlhttp;
function createRequest() {
if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
}
createRequest();
function sendRequest()
{
if(xmlhttp)
{
xmlhttp.open("GET", "URL", true);
xmlhttp.send(null);
xmlhttp.onreadystatechange = getRequestAndManager;
}
}
function getRequestAndManager()
{
if (xmlhttp_request.readyState == 4) {// 收到完整的服务器响应
if (xmlRequest.status == 200) {
var requestReturnStr = xmlhttp.responseText;
var json = eval("("+requestReturnStr+")");
}
}
}
跨域请求(跨域端口也属于跨域,80和8080属于跨域)在火狐等标准浏览器中Status为0,而且responseText为"",所以要注意这个问题