• ajax请求获取实时数据


    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
    
            <script src="WebUI/js/clienthint.js"></script>
        </head>
    
        <body>
    
            <form>
                First Name:<input type="text" id="txt1" onkeyup="showHint(this.value)" />
            </form>
    
            <p>Suggestions: <span id="txtHint"></span></p>
    
        </body>
    </html
     1 var xmlHttp
     2 function showHint(str) {
     3     if (str.length == 0) {
     4         document.getElementById("txtHint").innerHTML = "";
     5         return;
     6     }
     7     xmlHttp =ttpObject()
     8     if (xmlHttp == null) {
     9         alert("您的浏览器不支持ajax");
    10         return;
    11     }
    12     var url = "getint.aspx";
    13     url = url + "?q=" + str;
    14     url += "&sid=" + Math.random();
    15     xmlHttp.onreadystatechange= stateChanged;
    16     xmlHttp.open("GET", url, true);
    17     xmlHttp.send(null);
    18         
    19 }
    20 function stateChanged() {
    21    
    22     if (xmlHttp.readyState == 4) {
    23         console.log(xmlHttp.responseText);
    24         document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
    25        
    26     }
    27 }
    28 function ttpObject() {
    29     var xmlHttp = null;
    30     try{
    31         xmlHttp=new XMLHttpRequest();
    32 
    33     }
    34     catch (e) {
    35         try{
    36             xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    37         }
    38         catch (e) {
    39             xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    40 
    41         }
    42     }
    43     return xmlHttp;
    44 
    45 }
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 using System.Web.UI;
     6 using System.Web.UI.WebControls;
     7 
     8 namespace DemoItem
     9 {
    10     public partial class getint : System.Web.UI.Page
    11     {
    12         protected void Page_Load(object sender, EventArgs e)
    13         {
    14             string q = Request.QueryString["q"].ToString();
    15             Response.Write(q);
    16             Response.End();//终止执行代码
    17 
    18         }
    19     }
    20 }
  • 相关阅读:
    使用Dagger2做静态注入, 对比Guice.
    利用Cglib实现AOP
    Guice之IOC教程
    layui使用心得
    Protocol Buffer序列化对比Java序列化.
    IE之页面加载慢.
    浏览器Agent大全 (含IE 11, Edge)
    ASpectJ对AOP的实现
    Spring之AOP
    创建自己的加密货币MNC——以太坊代币(二)
  • 原文地址:https://www.cnblogs.com/tl2f/p/5579186.html
Copyright © 2020-2023  润新知