zoukankan      html  css  js  c++  java
  • AJAX基础知识

    ASP页面
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>AJAX之加法运算示例</title>
        <script type="text/javascript">
            var xmlHttp;
            function createXMLHttpRequest()
            {
                if(window.ActiveXObject)
                {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                else if(window.XMLHttpRequest)
                {
                    xmlHttp = new XMLHttpRequest();
                }
            }
            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);
            }
            function showResult()
            {
                if(xmlHttp.readyState==4)
                {
                    if(xmlHttp.status==200)
                    {
                        document.getElementById("result").value=xmlHttp.responseText;
                    }
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div style="text-align: center">
            <input id="num1" style=" 99px" type="text" value="0" onkeyup="addNumber();" />+<input id="num2" style=" 95px"
                type="text" value="0" onkeyup="addNumber();" />=<input id="result" style=" 99px" type="text" /></div>
        </form>
    </body>
    </html>


    Handler.ashx文件
    <%@ WebHandler Language="C#" Class="Handler" %>

    using System;
    using System.Web;

    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;
            }
        }

    }

  • 相关阅读:
    2014深圳华为机试剖析
    Tomcat J2ee 发布步骤
    Delphi实现无标题有边框的窗体
    所谓的湖南普天科技不是一般的坑
    struts2文件异步上传
    Adobe Flash Builder 4.7下载地址及破解补丁(32位&64位)
    从浏览器启动客户端程序
    delphi非IE内核浏览器控件TEmbeddedChrome下载|TEmbeddedChrome代码
    delphi中EmbeddedWB网页html相互调用(二)
    delphi中WEBBrowser网页html相互调用(一)
  • 原文地址:https://www.cnblogs.com/whitetiger/p/1088237.html
Copyright © 2011-2022 走看看