Simple Ajax example-no new sum calculation

Source: Internet
Author: User

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "SumNumber. aspx. cs" Inherits = "SumNumber" %>

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> example of sum without refreshing </title>
<Script type = "text/javascript">
Var xmlHttp;
Function createXMLHttpRequest ()
{
If (window. ActiveXObject)
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest)
{
XmlHttp = new XMLHttpRequest ();
}
}
// Processing Method
Function AddNumber ()
{
CreateXMLHttpRequest ();
Var url = "Handler. ashx? Num1 = "+ document. getElementById (" num1 "). value +" & num2 = "+ document. getElementById (" num2 "). value;
XmlHttp. open ("GET", url, true );
XmlHttp. onreadystatechange = ShowResult;
XmlHttp. send (null );
}
// Callback Method
Function ShowResult ()
{
If (xmlHttp. readyState = 4)
{
If (xmlHttp. status = 200)
{
Document. getElementById ("sum"). value = xmlHttp. responseText;
}
}
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div style = "text-align: center">
<Br/> simple example of the operation of the brushless NEX algorithm <br/>
<Br/>
<Input id = "num1" style = "width: pixel PX" type = "text" onkeyup = "AddNumber ();" value = "0"/>
+ <Input id = "num2" style = "width: 95px" type = "text" onkeyup = "AddNumber ();" value = "0"/>
= <Input id = "sum" style = "width: 97px" type = "text"/> </div>
</Form>
</Body>
</Html>

This instance also uses a program to process files. The Code is as follows:
<% @ WebHandler Language = "C #" Class = "Handler" %>

Using System;
Using System. Web;
Using System. Data;
Using System. Data. SqlClient;

Public class Handler: IHttpHandler
{

Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
Int result = Convert. ToInt32 (context. Request. QueryString ["num1"]) + Convert. ToInt32 (context. Request. QueryString ["num2"]);
Context. Response. Write (result );
}
 
Public bool IsReusable
{
Get
{
Return false;
}
}
}

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.