function XHR(){
this._xhr = null;
}
XHR.prototype.getInstance = function(){
if(window.ActiveXObject)
this._xhr = new ActiveXObject("Microsoft.XMLHttp");
if(window.XMLHttpRequest)
this._xhr = new XMLHttpRequest();
return this;
}
XHR.prototype.ajaxProc = function(url,callback,value){
this._xhr.open("POST",url,true);
this._xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
this._xhr.onreadystatechange = function(){
if(this.readyState==4 & this.status == 200){
this.responseText;
}
}
this._xhr.send("callback=" + callback + "&value=" + value);
this._xhr.close();
this._xhr = null;
}
解决办法:
请求的url是PHP的,须要PHP中echo:header(""Access-Control-Allow-Origin: *"");
请求html的,须要 <meta http-equiv="Access-Control-Allow-Origin" content="*">
其中CORS支持来访域名端口号,可以在目标资源中写入来源的端口号,比如:header("access-control-allow-origin:http://www.test.com:81");