Saturday, March 12th, 2011|
Have you ever noticed that when you lookup an example on google that you find a few hundred thousand, but never one that spills all the options? switches? parameters? It was starting to look like every jQuery ajax example was mysterious coming up with some new parameters. So, it seemed reasonable to share my quick reference chart – it helped me learn more about the methods inside the low level .ajax call:
Perform an asynchronous HTTP (AJAX) request.
settings: A map of options for the request:
*url: A string containing the URL to which the request is sent.
*async (optional): A Boolean indicating whether to perform the request asynchronously. Defaults to true.
* beforeSend (optional): A callback function that is executed before the request is sent.
*cache (optional): A Boolean indicating whether to allow the browser to cache the response. Defaults to true.
*complete (optional): A callback function that executes whenever the request finishes.
*contentType (optional): A string containing a MIME content type to set for the request. Defaults to application/x-www-form-urlencoded.context (optional): An object (typically a DOM element) to set as this within the callback functions. Defaults to window.
(below is newer elements >1.4)
*data (optional): A map or string that is sent to the server with the request.
*dataFilter (optional): A callback function that can be used to preprocess the response data before passing it to the success handler.
*dataType (optional): A string defining the type of data expected back from the server (xml, html, json, jsonp, script, or text).
*error (optional): A callback function that is executed if the request fails.
*global (optional): A Boolean indicating whether global AJAX event handlers will be triggered by this request. Defaults to true.
*ifModified (optional): A Boolean indicating whether the server should check if the page is modified before responding to the request. Defaults to false.
* jsonp (optional): A string containing the name of the JSONP parameter to be passed to the server. Defaults to callback.
*password (optional): A string containing a password to be used when responding to an HTTP authentication challenge.
*processData (optional): A Boolean indicating whether to convert submitted data from object form into query string form. Defaults to true.
*scriptCharset (optional): A string indicating the character set of the data being fetched; only used when the dataType parameter is jsonp or script.
*success (optional): A callback function that is executed if the request succeeds.
*timeout (optional): A number of milliseconds after which the request will time out in failure.
*type (optional): A string defining the HTTP method to use for the request, such as GET or POST. Defaults to GET.
*username (optional): A string containing a user name to be used when responding to an HTTP authentication challenge.
*xhr (optional): A callback function that is used to create the XMLHttpRequest object. Defaults to a browser-specific implementation.
This list was found, amongst a pile of results, while doing a (very extensive) google search. Here are some other helpful links that were found that have provided some useful examples:
This person has broken down the ‘useful’ functionality of ajax…. especially for using it in a real world situation.
Of course the original/latest jQuery api reference… don’t let it scare you. If you see a method (term) that you do not understand, then take a break – look up that “ONE TERM” in quotes… figure it out before moving forward. This ‘cheat sheet’ is basically some anonymous compilation of a variation of the api, but the way it was written helped me see all of the options. After taking each switch on this sheet, and researching it, it wasn’t a mysterious magical thing anymore. Hopefully this will prove useful to you too.
http://jsbin.u1st.us <–use jsbin to share your code!