# jQuery ajaxSetup() Method

jQuery AJAX Methods

## Example

Set the 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();
});
Try it yourself »

## Definition and Usage

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

## Syntax

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

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

Possible names/values in the table below:

Name | Value/Description
--- | ---
async | A 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
cache | A 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)
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 | Specifies data to be sent to the server
dataFilter(data,type) | A function used to handle the raw response data of the XMLHttpRequest
dataType | The data type expected of the server response.
error(xhr,status,error) | A function to run if the request fails.
global | A Boolean value specifying whether or not to trigger global AJAX event handles for the request. Default is true
ifModified | A Boolean value specifying whether a request is only successful if the response has changed since the last request. Default is: false.
jsonp | A string overriding the callback function in a jsonp request
jsonpCallback | Specifies a name for the callback function in a jsonp request
password | Specifies a password to be used in an HTTP access authentication request.
processData | A Boolean value specifying whether or not data sent with the request should be transformed into a query string. Default is true
scriptCharset | Specifies the charset for the request
success(result,status,xhr) | A function to be run when the request succeeds
timeout | The local timeout (in milliseconds) for the request
traditional | A Boolean value specifying whether or not 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 a username to be used in an HTTP access authentication request
xhr | A function used for creating the XMLHttpRequest object

## Try it Yourself - Examples

Specify an error handler for AJAX requests
How to use the error setting to specify an error handler for AJAX requests.

jQuery AJAX Methods

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples