Home > other >  In the jQuery ajax method
In the jQuery ajax method

Time:11-23

Knowledge of the list:
AJAX is a, what?
(1) the AJAX=asynchronous JavaScirpt and XML,
(2) the AJAX is a technology used to create the rapid dynamic web pages
(3) through a small amount of data exchange with the server in the background, AJAX can realize asynchronous update of web [AJAX is a without reloading the whole web page, will be able to update part of the web technology]
Second, AJAX is based on the Internet the vertebral (using the following technique combining) :
(1) the XMLHTTpRequest object (asynchronous interaction with the server data)
(2) the JavaScript/DOM (show/retrieve the information)
(3) the CSS style (set data)
(4) the XML (the style of the common data)
[AJAX applications is independent of browsers and platforms]
/*
Synchronous and asynchronous:
1, synchronous
- refers to a process when a request in the implementation of the
- if the request requires a period of time did not return to information, so the process will wait until the return information received to continue execution
Synchronous
-//request a 1 ms
//request 1 ms
//request three 1 ms
Asynchronous 1.3 ms
-
2, asynchronous
- refers to the process does not need to wait forever, but continue to perform the following operations, regardless of the other processes,
Returns will inform process system - when there is information processing, so that we can improve the efficiency of execution
Asynchronous implementation:
1, using HTML and CSS pages, express information
2, using the XMLHttpRequest and web server for the exchange of asynchronous data
3, use JavaScript DOM operation, realize the dynamic local refresh
*/
Three, ajax method ()
Common parameters:
(1) the types of options: Object
Optional, AJAX request Settings, all options are optional,
(2) the async types: Boolean
Default value: true, the default Settings, all requests for an asynchronous request, if you need to send a synchronous request, please switch option is set to false, the (synchronous request will lock the browser, users of other operations must wait only can perform the request is completed,)
(3) complete type: the function
- request after the completion of the callback function (request after the success or failure are all call)
- parameters: the XMLHttpRequest object and a string describing the type of request, (this is an ajax events)
(4) the contentType types: string
- the default value: "application/x - WWW - form - urlencoded", send information to the server content encoding type,
- the default value is suitable for most of the time, if you explicitly pass a content-type to $. Ajax () then it will be sent to the server (even if there is no data to be sent),
(5) data types: string
- send data to the server, request will be automatically converted into a string format,
- GET requests will be attached to the URL, after see processData option to prohibit the automatic conversion,
(6) the datatype types: string
- expected server returns the data type,
- if not specified, the jQuery automatically according to the HTTP packet MIME information intelligent judgment, such as XML MIME type is identified as XML, in 1.4, the JSON will generate a JavaScript object, and the script will be executed this script,
- then the data will be according to the value returned by the server parsed, passed to the callback function,
(7) the error types: function
- the default value: automatic judgment (XML or HTML), request to call this function when failure,
- has the following three parameters: the XMLHttpRequest object, error messages, capture the exception object (optional),
- if an error occurred, error message (the second parameter) in addition to be null, also may be a "timeout", "error", "notmodified" and "parsererror",
(8) success types: function
- request after the success callback function,
- parameters: returned by the server, and according to the dataType parameter after processing the data; String describing the condition, (this is an ajax events)
(9) type type: string
- the default value: "GET"),
- request method (" POST "or" GET "), the default is "GET", note: other HTTP request methods, such as PUT and DELETE can also be used, but only part of the browser support,
(10) url types: string
- the default value: the current page address, send the request address,
Commonly used callback function:
(1) Success
- when the request after the call, the incoming data after the return, and a string containing success code,
(2) Complete
Call this function after - when the request is completed, no matter success or failure, the incoming XMLHttpRequest object, and a success or error code contains the string
With AJAX method to send data to the server:
- by default, the ajax request using the get method, if you want to use the POST method, can set the type parameter values, this option will also affect the contents of the data options how to send to the server, also can set the way (method:)
  • Related