Good programmer web front-end learning route sharing AJAX status code ajax.status and encapsulation
Good programmer web front-end learning route sharing AJAX status code ajax.status and encapsulation, AJAX status code description
1 reply: request received, continue processing
2customers: operation received successfully, analyzed and accepted
3 requests: the completion of this request must be further processed
4 invalid requests: the request contains an error syntax or cannot be completed
5 invalid request: the server failed to execute a fully valid request
100buy-the customer must continue to make requests
101Mel-the customer requires the server to convert the HTTP protocol version according to the request
200Mutual-deal succeeded
201Mui-prompt to know the URL of the new file
202 color-accept and process, but processing is not completed
203mer-the return information is uncertain or incomplete
204music-request received, but the return message is empty
205Mel-the server has completed the request, and the user agent must reset the currently browsed file
206Mel-the server has completed the GET requests of some users
300mura-requested resources are available in multiple places
301mer-Delete request data
302mi-request data was found at another address
303mer-customers are advised to visit other URL or access methods
304Mel-the client has executed GET, but the file has not changed
305music-the requested resource must be obtained from the address specified by the server
306Mel-the code used in the previous version of HTTP, no longer used in the current version
307 music-declare that the requested resource is temporarily deleted
400m-incorrect request, such as syntax error
401 color-request for authorization failed
402 color-keep valid Chargeto header response
403muri-request not allowed
404Mel-No files, queries, or URl found
405Mel-the method defined by the user in the Request-Line field is not allowed
406Mel-the requested resource is inaccessible based on the Accept sent by the user
407 Mel-similar to 401, users must first be authorized on the proxy server
408Mel-the client did not complete the request within the hungry time specified by the user
409 color-the request could not be completed for the current resource status
410Mel-this resource is no longer available on the server and there is no further reference address
411Mel-the server rejects a user-defined request for Content-Length attributes
412Mel-one or more request header fields are incorrect in the current request
413Mel-the requested resource is larger than the size allowed by the server
414Mel-the requested resource URL is longer than the length allowed by the server
415Mel-request resource does not support request project format
416 range-the request contains the Range request header field, there is no range indication value within the scope of the current request resource, and the request does not contain the If-Range request header field
417Mel-the server does not meet the expected value specified in the request Expect header field. If it is a proxy server, it may be that the server at the next level cannot meet the request.
500mura-an internal error occurred on the server
501Mel-the server does not support the requested function
502Mel-the server is temporarily unavailable, sometimes to prevent system overload
503mura-server overload or suspension of maintenance
504Mel-the gate is overloaded and the server uses another gate or service to respond to the user. The set value of waiting time is long.
505Mel-the server does not support or reject the HTTP version specified in the request header
After learning the status code, we can do some things:
1.var AJAX=new XMHttprequert ()
/ / dialing: set request parameters
2.AJAX.open ('get','data/test.json',true)
3. Ajax.onreadystatechange = function ()
{
If (ajax.readyState = = 4 & & ajax.status = = 200)
{
Func_succ (ajax.responseText)
}
Else
{
/ / alert ("ajax faild readyState:" + ajax.readyState+ "status:" + ajax.status)
}
}
4.ajax.send (null)
Compatibility and Encapsulation of AJAX
Function InitAjax () {
Var ajax=false
Try {
Ajax = new ActiveXObject ("Msxml2.XMLHTTP")
}
Catch (e) {
Try {
Ajax = new ActiveXObject ("Microsoft.XMLHTTP")
}
Catch (E) {
Ajax = false
}
}
If (! ajax & & typeof xMLHttpRequestrated undefined) {
Ajax = new XMLHttpRequest ()
}
Return ajax
}
Function DoAjaxGet (ajax, url, func_succ) {
Ajax.open ("GET", url, true)
Ajax.onreadystatechange = function () {
If (ajax.readyState = = 4 & & ajax.status = = 200) {
Func_succ (ajax.responseText)
} else {
/ / alert ("ajax faild readyState:" + ajax.readyState+ "status:" + ajax.status)
}
}
Ajax.send (null)
}
Function DoAjaxPost (ajax, url, func_succ, post_datas) {
Ajax.open ("POST", url, true)
Ajax.onreadystatechange = function () {
If (ajax.readyState = = 4 & & ajax.status = = 200) {
Func_succ (ajax.responseText)
} else {
Alert ('ajax faild readyState:'+ajax.readyState+ "status:" + ajax.status)
}
}
Ajax.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded")
Ajax.send (post_datas)
}
Ajax cache problem: clear cache with timestamp
DoAjaxGet (ajax,'data/test.txt?t='+ new Date (). GetTime (), aaa)