XMLHttpRequest cannot load an URL with jQuery

You can’t do a XMLHttpRequest crossdomain, the only “option” would be a technique called JSONP, which comes down to this:

To start request: Add a new <script> tag with the remote url, and then make sure that remote url returns a valid javascript file that calls your callback function. Some services support this (and let you name your callback in a GET parameters).

The other easy way out, would be to create a “proxy” on your local server, which gets the remote request and then just “forwards” it back to your javascript.

edit/addition:

I see jQuery has built-in support for JSONP, by checking if the URL contains “callback=?” (where jQuery will replace ? with the actual callback method). But you’d still need to process that on the remote server to generate a valid response.

Leave a Comment