A simple example of asynchronous request data

Source: Internet
Author: User

Core JS Code of asynchronous request

Function callserver (type, URL, isasync, user, password ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
// The open method contains five parameters. The first three parameters are required, and the last two parameters are optional (provided when the server requires authentication)
// The data transmission method is get or post, the URL of the Service webpage, and whether the request is asynchronous (true by default, that is, asynchronous execution. False, synchronous execution), user name (can be omitted), user password (can be omitted)
XMLHTTP. Open (type, URL, isasync, user, password );
// If the open method is defined as post, you can define form-based upload.
If (type. touppercase = "Post "){
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
// XMLHTTP. Send (strparamstring );
}
If (isasync) {// Asynchronous Method
XMLHTTP. onreadystatechange = update;
XMLHTTP. Send ();
}
Else {// Synchronization Method
XMLHTTP. Send ();
If (XMLHTTP. Status = 200 ){
// Responsetext: uses the returned message as a text string;
// Responsebody: uses the returned message as the HTML document content;
// Responsexml: regards the returned message as an XML document, which is used when the server response message contains XML data;
// Responsestream: treats the returned message as a stream object.
VaR ret = XMLHTTP. responsetext; // This is the data returned from the synchronous request.
}
}
}
// Asynchronous callback function
Function Update (){
If (XMLHTTP. readystate = 4 ){
VaR response = XMLHTTP. responsetext; // This is the data returned from the asynchronous request.
}
}

Core background code (create An ASPX page for processing requests ):

Protected void page_load (Object sender, eventargs E)
{
String ret = "this is Microsoft. XMLHTTP"; // here is the data you want to organize.
Response. Write (RET );
Response. End ();
}

Front-End call code:

VaR url = "webserver. aspx"; // you can attach parameters and obtain the parameters in the background.
Callserver ("Post", URL, true ,"","");

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.