Javascript-based browser-compatible Ajax

Source: Internet
Author: User

<Script language = "JavaScript" type = "text/JavaScript">

// Create an XMLHTTPRequest object compatible with the browser

Function createxmlhttp ()
{
VaR XMLHTTP;
If (window. activexobject)
{
VaR arr = ["msxml2.xmlhttp. 6.0", "msxml2.xmlhttp. 5.0 ",
"Msxml2.xmlhttp. 4.0", "msxml2.xmlhttp. 3.0", "msxml2.xmlhttp", "Microsoft. XMLHTTP"];
For (VAR I = 0; I <arr. length; I ++)
{
Try
{
XMLHTTP = new activexobject (ARR [I]);
Return XMLHTTP;
}
Catch (error)
{

}
}
}
Else
{
Try
{
XMLHTTP = new XMLHttpRequest ();
Return XMLHTTP;
}
Catch (othererror)
{

}
}
}
Function xmlpost ()
{
VaR XMLHTTP = createxmlhttp ();
VaR fileurl = 'checkunamehandler. ashx? Uname = '+ username. value; // URL of the accepted value
XMLHTTP. Open ('get', fileurl, true );

XMLHTTP. onreadystatechange = function (){
If (XMLHTTP. readystate = 4 & XMLHTTP. Status = 200)
{
VaR result = XMLHTTP. responsetext;
Alert (result );
If (result = '0 ')
{
Spcheckname. innerhtml = 'user name is available! ';
Document. getelementbyid ('<% = This. btnsub. clientid %>'). Disabled = '';
}
Else if (result = '1 ')
{
Spcheckname. innerhtml = 'user name occupied! ';
Document. getelementbyid ('<% = This. btnsub. clientid %>'). Disabled = 'Disabled ';
}
}
Else
{
Spcheckname. innerhtml = 'the operation is too fast! Data Verification Failed! ';
}
}

XMLHTTP. Send ('');

}

</SCRIPT>

Note:

XMLHTTP. status value (HTTP status table)
0 **: not started
1 **: request received, continue processing
2 **: The operation is successfully received, analyzed, and accepted.
3 **: the request must be further processed.
4 **: The request contains an error syntax or cannot be completed
5 **: the server failed to execute a fully valid request.

100 -- the customer must continue to send the request
101 -- the client requests the server to convert the HTTP protocol version according to the request

200 -- transaction successful
201 -- prompt to know the URL of the new file
202 -- accept and process, but not complete
203 -- the returned information is uncertain or incomplete
204 -- the request is received, but the returned information is null.
205 -- when the server completes the request, the user agent must reset the file that has been browsed.
206 -- the server has completed some users' GET requests

300 -- the requested resources can be obtained in multiple places
301 -- Delete request data
302 -- request data found at other addresses
303 -- we recommend that you access other URLs or access methods.
304 -- the client has executed get, but the file has not changed
305 -- the requested resource must be obtained from the address specified by the server
306 -- used in the previous HTTP VersionCode, Which is not used in the current version
307 -- declaring temporary deletion of requested resources

400 -- incorrect request, such as syntax error
401 -- authorization request failed
402 -- retain valid chargeto header response
403 -- the request is not allowed
404 -- no file, query, or URL found
405 -- the method defined in the request-line field is not allowed.
406 -- the requested resource is inaccessible due to the user's accept drag.
407 -- similar to 401, the user must first be authorized on the Proxy Server
408 -- the client did not complete the request within the specified time
409 -- the request cannot be completed due to the current resource status
410 -- this resource is no longer available on the server and there is no further reference address
411 -- the server rejects the User-Defined Content-Length attribute request
412 -- one or more request header fields are incorrect in the current request
413 -- the requested resource is larger than the size allowed by the server
414 -- the requested resource URL is longer than the length allowed by the server
415 -- the requested resource does not support the format of the requested project
416 -- The request contains the range request header field. There is no range indication value in the current request resource range, and the request does not contain the IF-range request header field.
417 -- the server does not meet the expectation specified in the header field of the response CT request. If it is a proxy server, it may be that the next-level server cannot meet the request

500 -- Internal error occurred on the server
501 -- the server does not support the requested function
502 -- the server is temporarily unavailable, sometimes to prevent system overload
503 -- server overload or service suspension
504 -- the gateway is overloaded. The server uses another gateway or service to respond to the user. The waiting time is long.
505 -- the server does not support or reject the specified HTTP version in the Request Header

1xx: Information Response class, indicating that the request is received and processed continuously
2XX: Successful response class, indicating that the action is successfully received, understood, and accepted
3xx: redirect response class. To complete the specified action, you must accept further processing.
4xx: client error. The client request contains a syntax error or cannot be correctly executed.
5xx: server error. The server cannot correctly execute a correct request.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.