您好我想從服務器1做Ajax請求到服務器2的JavaScript Ajax代碼:從服務器1中的JavaScript執行阿賈克斯服務器2
function sendGet(path) {
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState === 4 && xmlhttp.status === 200) {
return(xmlhttp.responseText);
}
};
xmlhttp.open("GET", path, true);
xmlhttp.send();
}
鉻回報: XMLHttpRequest cannot load http://itaysharon.esy.es/jsdb.php?user=test&pass=1234. No 'Access-Control-Allow-Origin' header is present on the requested resource.Origin 'null' is therefore not allowed access.
我使用純JS和我想保持這種方式。 有什麼方法可以解決它在JS? THX
是在服務器中啓用CORS 2? – mido
不,我猜不是 –
你有兩臺服務器嗎?你是否允許在兩端編輯文件? –