• 深入浅出Ajax(一)


    客户端:

      <script type="text/javascript">
            window.onload = initPage;
    
            function initPage()
            {
                var btn = document.getElementById("btnOK");
                btn.onclick = function ()
                {
                    getDetails(this.title);//按钮单击发送请求
                }
            }
    
            function getDetails(obj)
            {
                request = createRequest(); //创建请求对象
                if (request == null)
                {
                    alert("没有请求对象!");
                    return;
                }
                var url = "DetailForm.aspx?title=" + escape(obj);//向何处发请求
                request.open("GET", url, true); //请求方式
                request.onreadystatechange = displayDetails;//函数引用,设置回调函数
                request.send(null);//没有随请求发送额外东西
            }
    
            function displayDetails()
            {
                if (request.readyState == 4)
                {
                    if (request.status == 200)
                    {
                        document.getElementById("btnOK").value = request.responseText;
                    }
    
                }
            }
            function createRequest()
            {
                try
                {
                    request = new XMLHttpRequest();
                } catch (tryMS)
                {
                    try
                    {
                        request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (otherMS)
                    {
                        try
                        {
                            request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (failed)
                        {
                            request = null;
                        }
                    }
                }
                return request;
            }
    
            //完全看不到页面的刷新,却从服务器端拿回了数据!
        </script>
    <body>
        <form id="form1" runat="server">
            <div>
                <input type="button" id="btnOK" value="Ok" title="确定" />
            </div>
        </form>
    </body>

    服务端:

     public partial class DetailForm : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                string str = Request.QueryString["title"];
                if (str != null && str != "")
                {
                    Response.Write("new_" + str);
                }
                else
                {
                    Response.Write("nothing");
                }
                Response.End();
            }
        }
  • 相关阅读:
    oracle 11g 数据库密码大小写敏感性更改
    OGG 课程 第一课
    xmanager
    一步一步在RHEL6.5+VMware Workstation 10上搭建 oracle 11gR2 rac + 物理 dg
    GTONE安装Eclipse插件
    JDK安装与环境变量配置
    JAVA基础
    操作符总结
    物理CPU查看方式
    SQL SERVER性能调优
  • 原文地址:https://www.cnblogs.com/hometown/p/3237164.html
Copyright © 2020-2023  润新知