Search code examples
ajaxangularjscross-site

Can I request by ajax to different domains or is that a cross-site limitation?


I am planning to develop a project which will have access to different services placed in different domains using ajax, so that it may get different types of data from each of them.

At the beginning I thought that due to cross-site scripting that can't be done so I would have to use a different approach or maybe use a bridge (make the calls to my server which will behind the scenes call the others) but the bridge would become a performance issue.

But then I was testing Angular using Google's API and realized that it just works. I mean, I could make AJAX calls to my localhost (though I know localhost may work just because it's localhost) using a script loaded from googleapis.com.

Now I wonder if it is possible or not to have a page with ajax calls to other domains like: mail.mydomain.com, profiles.mydomain.com, media.mydomain.com, and so on. And if so, can that be done just like that or are there any limitations? Because I remember that some years ago I had trouble doing things like that due to the cross-script block.

Just in case it helps, I'm planning to use Angular to get the data and paint it over the views.

Thanks.


Solution

  • Yes, it has limitations, but can be relieved easily. Set HTTP header "Access-Control-Allow-Origin" to "*" does it.