Created
August 2, 2014 00:55
-
-
Save jeffjohnson9046/458a0c22192f1ce9eaf3 to your computer and use it in GitHub Desktop.
jQuery JSONP Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is something I ALWAYS forget about, so hopefully this Gist will serve as a reminder. Whenever you get the "Access-Control-Allow-Origin" | |
// error, that's because you're trying to make a cross-domain AJAX request, which is a big no-no in the world of the internet. | |
// So, after spending WAY more time than I care to admit trying to address this, I remembered that JSONP is the answer. Here's | |
// how to do it: | |
$.ajax({ | |
url: [/* whatever your URL is */], | |
/*type: 'GET',*/ // seems superfluous - .ajax uses GET by default. | |
dataType: 'jsonp', | |
/*crossDomain: true,*/ // seems to work fine without this. | |
data: { /* an object with whatever data you need to pass along in your JSONP request */ }, | |
success: function(response) { | |
/* do something meaningful with the result. */ | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment