
- jQuery Tutorial
- jQuery - Home
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery DOM Manipulation
- jQuery - DOM
- jQuery - Add Elements
- jQuery - Remove Elements
- jQuery - Replace Elements
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
- jQuery Useful Resources
- jQuery - Questions and Answers
- jQuery - Quick Guide
- jQuery - Useful Resources
- jQuery - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery - jQuery.ajax( options ) Method
Description
The jQuery.ajaxSetup( options ) method sets global settings for future AJAX requests.
Syntax
Here is the simple syntax to use this method −
$.ajaxSetup( options )
Parameters
Here is the description of all the parameters used by this method −
options − A set of key/value pairs that configure the Ajax request. All options are optional.
Sr.No. | Option & Description |
---|---|
1 | async A Boolean indicating whether to perform the request asynchronously. The default value is true. |
2 | beforeSend A callback function that is executed before the request is sent. |
3 | complete A callback function that executes whenever the request finishes. |
4 | contentType A string containing a MIME content type to set for the request. The default value is application/x-www-form-urlencoded. |
5 | data A map or string that is sent to the server with the request. |
6 | dataFilter A function to be used to handle the raw responsed data of XMLHttpRequest. This is a pre-filtering function to sanitize the response. |
7 | dataType A string defining the type of data expected back from the server (xml, html, json, or script). |
8 | error A callback function that is executed if the request fails. |
9 | global A Boolean indicating whether global AJAX event handlers will be triggered by this request. The default value is true. |
10 | ifModified A Boolean indicating whether the server should check if the page is modified before responding to the request. |
11 | jsonp Override the callback function name in a jsonp request. |
12 | password A password to be used in response to an HTTP access authentication request. |
13 | processData A Boolean indicating whether to convert the submitted data from an object form into a query-string form. The default value is true. |
14 | success A callback function that is executed if the request succeeds. |
15 | timeout Number of milliseconds after which the request will time out in failure. |
16 | timeout Set a local timeout (in milliseconds) for the request. |
17 | type A string defining the HTTP method to use for the request (GET or POST). The default value is GET. |
18 | url A string containing the URL to which the request is sent. |
19 | username A username to be used in response to an HTTP access authentication request. |
20 | xhr Callback for creating the XMLHttpRequest object. Defaults to the ActiveXObject when available (IE), the XMLHttpRequest otherwise. |
Example
Assuming we have following HTML content in result.html file −
<h1>THIS IS RESULT...</h1>
Following is a simple example a simple showing the usage of this method. Here we make use of success handler to populate returned HTML −
<html> <head> <title>The jQuery Example</title> <script type = "text/javascript" src = "https://www.tutorialspoint.com/jquery/jquery-3.6.0.js"> </script> <script type = "text/javascript" language = "javascript"> $(document).ready(function() { $("#driver").click(function(event){ // Do global setting. $.ajaxSetup({ url: "result.html" }); $.ajax( { success:function(data) { $('#stage').html(data); } }); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id = "stage" style = "background-color:#cc0;"> STAGE </div> <input type = "button" id = "driver" value = "Load Data" /> </body> </html>
This will produce following result −