zoukankan      html  css  js  c++  java
  • XMLHttpRequest 实现无刷新更新页面数据

    xmlhttp1.aspx

    js 如下:


    function createXMLHttpReq()

     {
            var xmlHttp=null;
           
            try
            {
                // Firefox, Opera 8.0+, Safari, IE7
                xmlHttp=new XMLHttpRequest();
            }
            catch(e)
            {
                // Old IE
                try
                {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e)
                {
                    xmlHttp=null;
                    alert ("Your browser does not support XMLHTTP!");
                }
            }
            return xmlHttp;

    }

    function showHint(str)
    {
            if (str.length==0)
            {
                document.getElementById("txtHint").innerHTML="";
                return;
            }
           
            xmlHttp=createXMLHttpReq();
           
            url="xmlhttp2.aspx?c=" + str + "&sid=" + Math.random();
            xmlHttp.open("GET",url,false);
            xmlHttp.send(null);
            document.getElementById("txtHint").innerHTML=xmlHttp.responseText;

    }

    Body 如下:


    <input type="text" id="txt1" onkeyup="showHint(this.value)" />
    <div id="txtHint"></div>

    xmlhttp2.aspx

    Body中不能包含 Form

    xmlhttp2.aspx.cs


    Response.Write(Request["c"].ToString()+" Hello");

  • 相关阅读:
    HDU-2067-小兔的棋盘
    HDU-1861-游船出租
    C语言笔记
    P1164 小A点菜
    P1028 数的计算
    P1217 [USACO1.5]回文质数 Prime Palindromes
    P1088 火星人
    P2392 kkksc03考前临时抱佛脚
    P3799 妖梦拼木棒
    First Step (ファーストステップ)
  • 原文地址:https://www.cnblogs.com/abccome/p/3344597.html
Copyright © 2011-2022 走看看