Skip to content

Instantly share code, notes, and snippets.

@ryanmcgrath
Created January 21, 2012 14:02
Show Gist options
  • Save ryanmcgrath/1652861 to your computer and use it in GitHub Desktop.
Save ryanmcgrath/1652861 to your computer and use it in GitHub Desktop.
$.ajax breakdown for cross-domain requests.
// An AJAX query is broken down like this...
$.ajax({
// This means we're going to pull data; if you're
// creating something new on the server, this'll be POST
type: "GET",
// This tells jQuery to use a cross-domain fetching trick
dataType: "jsonp",
// The BASE URL we want to query data from
url: '',
// The params object you created
data: { /* your object here */ },
// A function to call when the query is completed
success: function(tweets) {
// Do stuff
},
// A function to call if things blow up completely - like Twitter is down
error: function() {
alert("OH GOD THE TWITTERS IS DOWN");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment