Ajax status code,xhr.readyState
0: unsent not sent, Ajax object created, default value 0
1: Opened Executionxhr.open
2: headers _ received the current ajax request has been sent and the corresponding header information returned by the server side has been received
3: Loading Response Body Content Returning
4: Done’s corresponding subject content has been returned to the client
Http network status code
HTTP network status codeTo record the status of the information returned by the current serverxhr.status
200: Identify Success Status
In order to3The beginning also indicates success, but the server side has done special treatment
301: Permanent Transfer (permanent redirect), Applied to Domain Name Transfer
302: Temporary Transfer (Temporary Redirection, 307 in the new version of Http is Temporary Redirection) for server load balancing
304: Obtain data from the browser cache and cache infrequently updated data into the browser
In order to4First, identify the failure status, mostly at the client
400: request parameter error
401: No access
404: Access address does not exist
In order to5First, identify the failure status, mostly on the server side
500: internal serverrerror unknown server error
503:Service Unavailable Server Overloaded
Ajax Common Attributes and Methods
Topic: How many methods are supported in Ajax?
state
-
readyState
: Stores the current Ajax status code -
response/responseText/responseXML
: Receive the corresponding subject content returned by the server-
responseText
Most commonly, the received results are in string format (the data returned by the general server are JSON format strings) -
responseXML
Receiving XML document data
-
-
status
: Record the HTTP status code returned by the server side -
statusText
: Description of the return status code -
timeout
: Sets the timeout for the current Ajax request
Method
-
abort()
: Forcibly Interrupt Ajax Requests -
getAllResponseHeaders()
: Get all response header information (the result is string text) -
getResponseHeader(key)
: Gets the corresponding header information for the specified attribute name -
open()
: Opens a URL address -
overrideMimeType()
: Overwrite MIME Type of Data -
send()
: Send Ajax Request -
setRequestHeader(key,value)
: Set request header information
Events
-
onabort()
: When Ajax is interrupted, the request triggers this event -
onreadystatechange
: Ajax state changes, triggering this event -
ontimeout
: Triggers this event when the Ajax request times out
JS encoding and decoding
(unencrypted) normal encoding and decoding
-
escape/unescape
: Encode and decode Chinese characters (JS support only) -
encodeURI/decodeURI
: All programming languages are supported encodeURIComponent/decodeURIComponent
Encoding and decoding
URL question mark pass parameter,encodeURI
Some special characters cannot be encoded, only can be usedencodeURLComponent
To deal with
- Reversible encryption
- Irreversible encryption (based on MD5 encryption, the result of MD5 encryption may be encrypted twice)
Synchronization and Asynchronous of Ajax
Ajax Task: Send Request to Receive Corresponding Subject Content (Full HTTP Transaction)
-
xhr.send()
: Task End -
xhr.readyState===4
: Task End
Encapsulation of Ajax Class Library
-
url
: request API address -
method
: request method GET/POST -
dataTpye
: Presets the result type and does not affect the return of the server (the server normally returns JSON format strings). If the preset isjson
The class library converts the string returned by the server into a json object -
cache
: Set whether to clear the cache, valid only for GET series requests, default isTRUE
Do not clear cache, manually set toFALSE
, JQ class library appends a random number at the end of the request URL to clear the cache -
data
: Pass some information to the server through DATA (GET request splices the content in DATA at the end of URL and passes it to the server through greeting and parameter passing, POST request passes the content to the server in the request body) (DATA can be set in two formats: string and object) -
async
: Set synchronous or asynchronous, the default is TRUE, which means asynchronous and FALSE is synchronous. -
success
: Request the callback function to be executed successfully and pass the obtained result to the callback function as an argument -
error
: request error triggers callback function -
complete
: done, triggering callback function