Search code examples
javascripthtmlajaxcross-domainsame-origin-policy

cross-domain ajax to foreign domain with pure JS and html


First of all - I have read teens of SO similar questions and other googled pages / blogs.

There was many ways to make cross-domain communication work, but is there something that lets me do that, when I'm unable to modify page (for example http://www.imdbapi.com/?t=True%20Grit&y=1969 ) that I want call?

Can I use postMessage solution (this method looked best to me) without ANY modification in http://www.imdbapi.com/?t=True%20Grit&y=1969 ? It looks like it has no helper page (one of the methods).

I don't want to use any 3rd party library / php script / etc - just pure html and javascript - is it possible to call such a 'immutable' page? ... and parse it on my own page (simple iframe is ofc not enough)

Please help - my huge research leave me with nothing


Solution

  • ok, here's the thing. what that did is requested data from the same domain. inter-subdomain and subdomain-domain requests are not "same domain", just to make things clear. Since that page was "same-domain", it was possible without a helper.

    AJAX does not allow cross-domain requests. as far as i know, there are methods that allow cross-domain requests (such as helper pages)

    currently, jsonp is supported by jQuery and you can do it like this:

    http://api.jquery.com/jQuery.getJSON/

    look for in the page: "Loads the four most recent cat pictures from the Flickr JSONP API."

    or see reference:

    http://en.wikipedia.org/wiki/JSONP