ajax()
방법을 사용하여
subdomain
에 AJAX를 호출 할
jQuery를 : resp == { status:0, readyState: 0, responseText : '', statusText: 'error' }
도메인 간 아약스 WTH
ajax()
방법을 사용하여
subdomain
에 AJAX를 호출 할
jQuery를 : resp == { status:0, readyState: 0, responseText : '', statusText: 'error' }
도메인 간 아약스 WTH
하위에 내가 http://domain.com/
$.ajax({
crossDomain: true,
url:'https://sub.domain.com/',
success: function(response) {
alert('ok');
},
error: function(resp) {
console.log(resp);
}
});
에서 호출하지만이 작동하지 않습니다 호출 오류 기능 도메인 아약스 호출은 또한 교차 도메인입니다. 동일한 장소 (예 : example.com 및 www.example.com)를 가리키는 경우에도 마찬가지입니다. 그들은 (보통) 같은 장소를 가리 킵니다. 우리는 그것들을 같은 것으로 봅니다. 그러나 Ajax 호출에서는 크로스 도메인으로 간주됩니다.
crossdomain ajax에 대한 검색을 수행하면 계속 진행할 수 있습니다.
이 목적으로 CORS를 사용할 수 있습니다.
예제 코드 :
jQuery.support.cors = true;
function CrosDom_ajax(url) {
if (window.XDomainRequest
&& $.browser.msie
&& $.browser.version < 10) {
xdr = new XDomainRequest();
if (xdr) {
xdr.onload = function() {
alert(xdr.responseText);
};
xdr.open("get", url);
xdr.send();
}
}
else {
$.ajax({
url: url,
success: function (response) {
},
error: function (data) {
}
});
}
}
는 또한 서버 측에 다음 코드를 작성할 필요가 허용하는 크로스 도메인 액세스
Response.AppendHeader("Access-Control-Allow-Origin", "*");