Native Javascript+ajax

Source: Internet
Author: User

On the internet to find a few posts, but due to the level of limited, tossing a meeting to achieve a small program. After theoretical understanding, coupled with an actual demo, it is easy for beginners to understand Ajax.

I paste the specific code, convenient and I like the first person to learn understanding.

The procedure is as follows:

The first is the foreground code of the request page:

<! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Server"><meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/> <title></title> <script type="Text/javascript">function createxhr () {varXHR =NULL; Try {                //Firefox, Opera 8.0+, safari,ie7+XHR =NewXMLHttpRequest (); }            Catch(e) {//Internet Explorer                Try{XHR=NewActiveXObject ("msxml2.xmlhttp"); }                Catch(e) {Try{XHR=NewActiveXObject ("Microsoft.XMLHTTP"); }                    Catch(e) {xhr=NULL; }                }            }            returnXHR; } function Setcontainer (text) {document.getElementById ("Container"). Value =text; } function Testajax () {varXHR =createxhr (); Xhr.onreadystatechange=function () {if(Xhr.readystate = =4&& Xhr.status = = $) {Setcontainer ('Original Ajax:'+xhr.responsetext); //alert (xhr.status);}} xhr.open ('Get','Webform2.aspx?action=gettime',true);        Xhr.send (); }    </script>"Button1"Type="Button"Value="Test Ajax"onclick="Testajax ()"/> <input id="Container"Type="text"/></body>

Then the background data processing of the requested page

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Xml.Linq;namespace_02{ Public Partial classWebForm2:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) {            stringAction = request.querystring["Action"].             ToString (); if(request.querystring["Action"]!=NULL)            {                Switch(action) { Case "GetTime": Response.Write (GetTime ());  Break;  Case "getDate": Response.Write (GetDate ());  Break ;            } response.end (); }        }        Private stringGetTime () {returnDateTime.Now.ToShortTimeString (); }        Private stringGetDate () {returnDateTime.Now.ToShortDateString (); }     }}

Native Javascript+ajax

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.