Skip to content

Instantly share code, notes, and snippets.

@wehrhaus
Created July 1, 2014 14:20
Show Gist options
  • Save wehrhaus/9af6f020700351b42b1b to your computer and use it in GitHub Desktop.
Save wehrhaus/9af6f020700351b42b1b to your computer and use it in GitHub Desktop.
jQuery Ajax Template
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