zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    漫谈C语言结构体
    如何理解c和c++的复杂类型声明
    STM32 时钟系统
    STM32 系统架构
    运放参数的详细解释和分析-part1,输入偏置电流和输入失调电流【转】
    ROM、RAM、DRAM、SRAM、FLASH的区别?
    FATFS模块应用笔记
    关于I2C和SPI总线协议【转】
    USB编程概念
    Ubuntu手机识别
  • 原文地址:https://www.cnblogs.com/tl2f/p/5579186.html
Copyright © 2011-2022 走看看