Javascript examples for jQuery Method and Property:ajax
The ajax() method performs an asynchronous HTTP (AJAX) request.
All jQuery AJAX methods use the ajax() method.
$.ajax({name:value, name:value, ... })
The parameters specifies one or more name/value pairs for the AJAX request.
Possible names/values in the table below:
Name | Value | Description |
---|---|---|
async | Boolean value | whether the request should be handled asynchronous. Default is true |
beforeSend(xhr) | function | run before the request is sent |
cache | Boolean value | whether the browser should cache the requested pages. Default is true |
complete(xhr,status) | function | run when the request is finished after success and error functions |
contentType | string | The content type used when sending data to the server. Default is: "application/x-www-form-urlencoded" |
context | context | "this" value for all AJAX related callback functions |
data | data | data to be sent to the server |
dataFilter(data,type) | function | handle the raw response data of the XMLHttpRequest |
dataType | data type | data type expected of the server response. |
error(xhr,status,error) | function | run if the request fails. |
global | Boolean value | whether to trigger global AJAX event handles for the request. Default is true |
ifModified | Boolean value | whether a request is only successful if the response has changed since the last request. Default is: false. |
jsonp | string | A string overriding the callback function in a jsonp request |
jsonpCallback | string | a name for the callback function in a jsonp request |
password | string | a password to be used in an HTTP access authentication request. |
processData | Boolean value | whether data sent with the request should be transformed into a query string. Default is true |
scriptCharset | string | the charset for the request |
success(result,status,xhr) | function | A function to be run when the request succeeds |
timeout | number | The local timeout (in milliseconds) for the request |
traditional | Boolean value | whether to use the traditional style of param serialization |
type | string | the type of request. (GET or POST) |
url | string | URL to send the request to. Default is the current page |
username | string | a username to be used in an HTTP access authentication request |
xhr | function | A function used for creating the XMLHttpRequest object |
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $.ajax({url: "demo_ajax_load.txt", async: false, success: function(result){ $("div").html(result); }});//from ww w . j a v a 2 s.co m }); }); </script> </head> <body> <div><h2>Let AJAX change this text</h2></div> <button>Change Content</button> </body> </html>