Ajax from child domain
Ajax from child domain
Hi all,
I need to make a XHR from a child domain, for instance child.api.com -> api.com.
Normally that can be done by setting the document.domain attribute to the same base domain (api.com)
$.ajax({
url: url,
data: [],
beforeSend: function(jqXHR,settings){
document.domain = 'api.com';
console.log('before send:' + document.domain);
},
success: function(resp){
console.log('success!');
},
error: function(jqXHR,textStatus,errorThrown){
console.log('error: '+jqXHR.responseText);
},
dataType: 'json'
});
But this fails. This is the log:
before send:api.com
XMLHttpRequest cannot load
http://api.com/sites/sandbox/users/1/recommendations.json
. Origin
http://child.api.com
is not allowed by Access-Control-Allow-Origin.
index.html:56
error:
recommendations.json
Failed to load resource
What am I doing wrong?
Greetings,
Chielus
Topic Participants
michielgyssels