Asynchronous refresh implementation has a variety of ways, but also the use of a variety of JS framework, the following is implemented using the jquery framework Ajax to verify the existence of the user name
Jquery.ajax Overview
HTTP requests load remote data.
Implemented through the jquery underlying AJAX. Simple and easy-to-use high-level implementation see $.get, $.post, etc. $.ajax () returns the XMLHttpRequest object that it created. In most cases you do not need to manipulate the object directly, but in special cases you can use it to manually terminate the request.
$.ajax () has only one parameter: The parameter Key/value object, which contains the configuration and callback function information. Detailed parameter options see below.
Note: If you specify the DataType option, make sure that the server returns the correct MIME information (such as the XML return "Text/xml"). The wrong MIME type can cause unpredictable errors. See Specifying the Data Type for AJAX Requests.
Note: If datatype is set to script, all post requests will be converted to get requests at remote request (not under the same domain). (because it will be loaded using the DOM's script tag)
In JQuery 1.2, you can load JSON data across domains and use it to set the data type to JSONP. When calling a function using JSONP form, such as "myurl?callback=?" JQuery is automatically replaced? To the correct function name to execute the callback function. When the data type is set to "Jsonp", JQuery automatically invokes the callback function.
Parameter list:
Name of parameter |
Type |
Describe |
Url |
String |
(Default: Current page address) sends the requested address. |
Type |
String |
(Default: "Get") Request method ("POST" or "get"), default to "get". Note: Other HTTP request methods, such as put and DELETE, are also available, but only partially supported by browsers. |
Timeout |
Number |
Sets the request timeout (in milliseconds). This setting overrides the global setting. |
Async |
Boolean |
(Default: TRUE) The default setting is that all requests are asynchronous requests. If you need to send a sync request, set this option to false. Note that the synchronization request will lock the browser and the user's other actions must wait for the request to complete before it can be executed. |
Beforesend |
Function |
You can modify the functions of the XMLHttpRequest object before sending the request, such as adding a custom HTTP header. The XMLHttpRequest object is the only parameter. function (XMLHttpRequest) { This The options for this AJAX request } |
Cache |
Boolean |
(default: TRUE) JQuery 1.2 new functionality, set to false will not load request information from the browser cache. |
Complete |
Function |
The callback function (called when the request succeeds or fails) after the request completes. Parameters: XMLHttpRequest Object, Success message string. function (XMLHttpRequest, textstatus) { This The options for this AJAX request } |
ContentType |
String |
(Default: "application/x-www-form-urlencoded") the content encoding type when sending information to the server. Default values are appropriate for most applications. |
Data |
Object, String |
Data sent to the server. is automatically converted to the request string format. The GET request is appended to the URL. View the ProcessData option description to prevent this automatic conversion. Must be in the Key/value format. If you are an array, JQuery will automatically correspond to the same name for different values. such as {foo:["bar1", "Bar2"]} is converted to ' &foo=bar1&foo=bar2 '. |
DataType |
String |
The type of data expected to be returned by the server. If not specified, JQuery will automatically return Responsexml or responsetext based on the HTTP packet MIME information and pass as a callback function parameter, available values: "XML": Returns an XML document that can be processed with jQuery. HTML: Returns plain text HTML information, including script elements. Script: Returns the plain text JavaScript code. Results are not automatically cached. "JSON": Returns JSON data. "JSONP": Jsonp format. When calling a function using JSONP form, such as "myurl?callback=?" JQuery is automatically replaced? To the correct function name to execute the callback function. |
Error |
Function |
(Default: Automatic judgment (XML or HTML)) This method is called when a request fails. This method has three parameters: the XMLHttpRequest object, the error message, and (possibly) the error object being caught. function (XMLHttpRequest, textstatus, Errorthrown) { Typically, only one of the Textstatus and Errorthown has a value. This The options for this AJAX request } |
Global |
Boolean |
(default: TRUE) triggers a global AJAX event. Setting to FALSE will not trigger global AJAX events, such as Ajaxstart or Ajaxstop. Can be used to control different AJAX events |
Ifmodified |
Boolean |
(default: false) gets new data only when the server data changes. Use HTTP packet last-modified header information to determine. |
ProcessData |
Boolean |
(default: TRUE) by default, the data sent is converted to an object (technically not a string) to match the default content type "application/x-www-form-urlencoded". Set to False if you want to send DOM tree information or other information that you do not want to convert. |
Success |
Function |
callback function after successful request. This method has two parameters: the server returns the data, returns the status function (data, textstatus) { Data could be xmldoc, jsonobj, HTML, text, etc ... This The options for this AJAX request } |