Easy Tutorial
❮ Prop Jquery Event Keyup ❯

jQuery ajaxSetup() Method

jQuery AJAX Methods

Example

Set default URL and success function for all AJAX requests:

$("button").click(function(){
    $.ajaxSetup({
        url:"demo_ajax_load.txt",
        success:function(result){
            $("div").html(result);
        }
    });
    $.ajax();
});

Definition and Usage

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


Syntax

The parameter specifies settings for AJAX requests with one or more name/value pairs.

The table below lists possible name/values:

Name Value/Description
async Boolean value indicating whether the request is handled asynchronously. Default is true.
beforeSend(xhr) Function to run before sending the request.
cache Boolean value indicating whether the browser should cache the requested page. Default is true.
complete(xhr, status) Function to run when the request finishes (after success and error functions).
contentType The content type used when sending data to the server. Default is: "application/x-www-form-urlencoded".
context Specifies the "this" value for all AJAX-related callback functions.
data Data to be sent to the server.
dataFilter(data, type) Function to handle raw response data of XMLHttpRequest.
dataType Expected data type of the server response.
error(xhr, status, error) Function to run if the request fails.
global Boolean value indicating whether to trigger global AJAX event handlers. Default is true.
ifModified Boolean value indicating whether the request should succeed only if the response has changed since the last request. Default is false.
jsonp String overriding the callback function in a jsonp request.
jsonpCallback Specifies the name of the callback function for a jsonp request.
password Specifies the password used in an HTTP access authentication request.
processData Boolean value indicating whether data sent with the request should be converted to a query string. Default is true.
scriptCharset Specifies the character set of the request.
success(result, status, xhr) Function to run when the request succeeds.
timeout Sets the local timeout for the request (in milliseconds).
traditional Boolean value indicating whether to use the traditional style of param serialization.
type Specifies the type of request (GET or POST).
url Specifies the URL to send the request to. Default is the current page.
username Specifies the username used in an HTTP access authentication request.
xhr Function used to create the XMLHttpRequest object.

More Examples

Specify an error handler for an AJAX request


jQuery AJAX Methods

❮ Prop Jquery Event Keyup ❯