When it comes to web browser security, making cross domain requests is usually disallowed. I recently came across some advice in a book that suggests using XMLHTTPRequest only if you can host the files on the same domain as the requested page. If this isn't possible, it recommends looking for alternative methods.
Now, my questions are:
- What alternatives exist for cross-domain requests instead of XMLHTTPRequest?
- How does WebSockets fit into this equation? Can it be used for cross-domain requests?
UPDATE: I'm still unclear about this...
For instance, if I fetch a page from www.domain1.com and need to get some JavaScript code from www.domain2.com, my fetched page would need to include something like:
<script src="www.domain2.com/script.js"></script>
in order to circumvent cross domain restrictions.
Alternatively, I could utilize JSONP by making a request like:
However, I wonder: Does this approach escape cross domain limitations since I'm essentially pulling JS from a different domain?