1
그냥 원격 서버에 아약스 게시물 요청을 사용하여 데이터를 보내려고합니다. 다음 코드는 IE에서는 제대로 작동하지만 크롬에서는 제대로 작동하지 않습니다. 왜 ? "Origin http // localhost가 Access-Control-Allow-Origin에서 허용하지 않은"문제점은 무엇입니까? 크롬에서 어떻게 작동시킬 수 있습니까? 도와주세요.Ajax 게시물 요청이 크롬에서 작동하지 않습니다.
var http = new ajaxRequest();
var url = "http://abcd.abc.com/login";
var params = "username=name&password=pass&id=12345";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
window.alert(http.responseText);
}
}
http.send(params);
function ajaxRequest(){
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes[i])
}
catch(e){
//suppress error
}
}
}
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
return new XMLHttpRequest()
else
return false
}