Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created April 4, 2014 08:00
Show Gist options
  • Save Kcko/9970145 to your computer and use it in GitHub Desktop.
Save Kcko/9970145 to your computer and use it in GitHub Desktop.
Complete ajax
var jqxhr = $.ajax({
url: url,
type: "GET", // default is GET but you can use other verbs based on your needs.
cache: true, // default is true, but false for dataType 'script' and 'jsonp', so set it on need basis.
data: {}, // add your request parameters in the data object.
dataType: "json", // specify the dataType for future reference
jsonp: "callback", // only specify this to match the name of callback parameter your API is expecting for JSONP requests.
statusCode: { // if you want to handle specific error codes, use the status code mapping settings.
404: handler404,
500: handler500
}
});
jqxhr.done(successHandler);
jqxhr.fail(failureHandler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment