About three steps of AJAX

Source: Internet
Author: User

1. Define an AJAX request object, set the method for receiving the returned results, and asynchronously request a webpage from the server.

2. Define a webpage for AJAX requests (return result string)

3. Define the feedback method, receive the AJAX request and return the result string (called by the system), and update somewhere on the page!

Detailed code of the three steps (three controls, two TextBox, and one button are used)

<Script language = javascript>
Var xmlObj = null;
Function do_ajax_request ()
{// Defines an AjAx request object, sends an Ajax request asynchronously to the server (requesting a page), and specifies a feedback method for receiving returned results
If (window. XMLHttpRequest)
{
XmlObj = new XMLHttpRequest ();
}
Else if (window. ActiveXObject)
{
XmlObj = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Else
{
Alert ("your IE version is too old, please change your IE ");
Return;
}

// Specify a feedback method for receiving returned results
XmlObj. onreadystatechange = do_handle_ajax;

// Send Ajax requests asynchronously to the server (request a page)
XmlObj. open ('get', 'Get _ talkmsg. aspx ', true); // get_talkmsg.aspx is a page
XmlObj. send ('');
}


Function do_handle_ajax ()
{
If (xmlObj. readyState = 4) // if the status is 4, the returned result is
{
// Alert (xmlObj. responseText );

Document. all ("TextBox_all"). value = xmlObj. responseText;
// Alert (xmlObj. responseText );

}

}
SetInterval (do_ajax_request, 1000 );
</Script>

// Get_talkmsg.aspx LOAD event

Protected void Page_Load (object sender, EventArgs e)
{
Response. ContentType = "text/plain ";
Response. Write (Application ["msg"]. ToString ());
Response. End ();
}

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.