Ajax core technology code sharing _ajax related

Source: Internet
Author: User
Tags string format

Copy Code code as follows:

<script>
var xhr = ';
function Ajax ()
{
if (window. XMLHttpRequest)
{
var xhr = new xmlhttprequest;//Modern browser
}else
{
var xhr = new ActiveXObject (' microsoft.xmlhttp ');//ie
}
}
Ajax ()//1. Get Ajax objects

Xhr.onreadystatechange = function ()
{
if (xhr.readystate = = 4 && xhr.status = 200)
{
var data = Xhr.responsetext;//2. Judging status, receiving data (in string form), subsequent operations
}
}

Xhr.open (' Mode of request ', ' request address ', TRUE);//3. Asynchronous Transport connections
Xhr.send ([data]);//4. Send a request

Xhr.open (' Get ', ' demo.php?name=weichen&sex=0 ', TRUE);
Xhr.send ();

/*
Xhr.open (' POST ', ' demo.php ', TRUE);
Xhr.setresponseheader (' Content-type ', ' application/x-www-form-urlencoded ');
Xhr.send (' name=weichen&sex=0 ');
*/

member properties and member methods in the XHR object

Copy Code code as follows:

{

Member Properties:
HTTP status code for the status server response (for example, 200 or 404)
HTTP status code (OK or not found) returned as a string by the StatusText server response
ReadyState Browser requested status code (0 to 4)
Data results in string format for ResponseText server response
Data results in XML format for Responsexml server response
onReadyStateChange Ajax Request Events (event handlers that are invoked when readystate changes)
Mozilla's event handler function that is invoked when an error occurs during a onerror request
OnProgress event handler function called after content loading
Mozilla event handler called after the onload document has finished loading
Member Methods:
setRequestHeader (); Sets the header header information for the current request (adds a key/value pair for the message header to be sent to the server side)
Open (); Create a new request connection (initialize the Xhr object with Get, POST, URL, etc.)
Send (); Send a request (data that may need to be sent)
getResponseHeader ("server"); Returns the value of the specified HTTP header (such as server or last-modified)
Getallresponseheaser (); Returns a string of all HTTP headers separated by a newline character
Absort (); Terminate 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.