Simplest Ajax example code (complete comment)

Source: Internet
Author: User
Simplest Ajax example code (complete comment)
<Input type = "button" onclick = "ajaxtest ()" value = "ajax test"> <input type = "button" onclick = "document. getelementbyid ('weate '). innerhtml = ''" value = "hide"> <SCRIPT> // 1. initialize the request object // var XMLHTTP = new XMLHttpRequest () under Mozilla/Firefox; // var XMLHTTP = new activexobject ("Microsoft. XMLHTTP ") // alert (XMLHTTP); function ajaxtest () {// specify the page to open XMLHTTP. open ("get", "staticpage.html", true); // HTTP Request Method, URL, asynchronous or not // specifies the operation to be performed after the page is opened. XMLHTTP. onreadystatechange = mychange; // start to initiate a browser request. Mozilla must add null XMLHTTP. send (null);} // This function is the function mychange () to be called every time the state changes {// The request has been completed if (XMLHTTP. readystate = 4) {// alert (XMLHTTP. readystate); alert (XMLHTTP. responsetext); // update the content displayed in the corresponding HTML element // reference the document element in the page based on the ID. getelementbyid (element name) document. getelementbyid ('weate '). innerhtml = XMLHTTP. responsetext ;}</SCRIPT> <Div id = "Weather"> </div>

 

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.