jQuery Reference

Quick Reference

The .ajaxSetup() method sets default values for future AJAX requests.

<!-- html element to place output -->
<p id="my_output"></p>
// on button click get some info and if successful place it in the HTML element
$('button').click(function() {
    $.ajaxSetup({
        url: 'test.txt',
        success: function(result) {
            $('#my_output').html(result);
        }
    });
    $.ajax();
});

Syntax

$.ajaxSetup({name:value, name:value, ... })

Note

It is generally good practice to place your jQuery code/function inside the document load function so that the action takes place ONLY after the document has finished loading. This ensures that all of the page elements that you may be selecting are in place before running the code on them.

Name/Value Pairs

NameValue/Description
asyncA Boolean value indicating whether the request should be handled asynchronous or not (default is true)
beforeSend(xhr)A function to run before the request is sent
cacheA Boolean value indicating whether the browser should cache the requested pages (default is true)
complete(xhr,status)A function to run when the request is finished (after success and error functions)
contentTypeThe content type used when sending data to the server. (default is: "application/x-www-form-urlencoded")
contextSpecifies the "this" value for all AJAX related callback functions
dataSpecifies data to be sent to the server
dataFilter(data,type)A function used to handle the raw response data of the XMLHttpRequest
dataTypeThe data type expected of the server response.
error(xhr,status,error)A function to run if the request fails.
globalA Boolean value specifying whether or not to trigger global AJAX event handles for the request (default is true)
ifModifiedA Boolean value specifying whether a request is only successful if the response has changed since the last request (default is false)
jsonpA string overriding the callback function in a jsonp request
jsonpCallbackSpecifies a name for the callback function in a jsonp request
passwordSpecifies a password to be used in an HTTP access authentication request
processDataA Boolean value specifying whether or not data sent with the request should be transformed into a query string (default is true)
scriptCharsetSpecifies the charset for the request
success(result,status,xhr)A function to be run when the request succeeds
timeoutThe local timeout (in milliseconds) for the request
traditionalA Boolean value specifying whether or not to use the traditional style of param serialization
typeSpecifies the type of request (GET or POST)
urlSpecifies the URL to send the request to (default is the current page)
usernameSpecifies a username to be used in an HTTP access authentication request
xhrA function used for creating the XMLHttpRequest object

jQuery Notes:

  • To use jQuery on your site, it must first be downloaded from the official jQuery site and linked to in your document <head>, or linked to via a CDN in your document <head>
  • It is generally good practice to place your jQuery code/function inside the document load function so that the action takes place ONLY after the document has finished loading
  • When using jQuery, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.