Greg Sabo

Making a JSONP request with jQuery

Why is it so hard to find a simple code example of how to do a JSONP request? StackOverflow fails hard at this.

Here it is:

$.ajax( dataType: 'jsonp', url: url ).done( (res) -> do_something(res) )

Make sure you’re calling $.ajax() and not $.get(). jQuery handles all of the document-appending and callback magic for you.

For the uninitiated, this is one thing you can do when you see this JS error: XMLHttpRequest cannot load Origin http://localhost:8005 is not allowed by Access-Control-Allow-Origin.