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).
1. $.ajax({
2. url: url,
3. data: [],
4. beforeSend: function(jqXHR,settings){
5. document.domain = 'api.com';
6. console.log('before send:' + document.domain);
7. },
8. success: function(resp){
9. console.log('success!');
10. },
11. error: function(jqXHR,textStatus,errorThrown){
12. console.log('error: '+jqXHR.responseText);
13. },
14. dataType: 'json'
15. });
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:56error: recommendations.jsonFailed to load resource
What am I doing wrong?
Greetings, Chielus