无刷新查询联动

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script language="JavaScript" type="text/javascript">
   HTTPRequest = function ()
   {
           var xmlhttp=null;
           try
           {
              xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
           }
           catch (_e)
           {
              try
               {
                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
               }
               catch (_E)
               {    }
           }
           if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
            {
             try
             {
                xmlhttp = new XMLHttpRequest();
             }
              catch (e)
              {
                xmlhttp = false;
           }  }
           return xmlhttp;
        }
        function ask(url, fieldToFill, lookupField)
         {
           var http = new HTTPRequest();
              http.open("GET", url, false);
           http.onreadystatechange = function()
           {
             handleHttpResponse(http, fieldToFill, lookupField)
           };
           http.send(null);
        }
        function handleHttpResponse(http, fieldToFill, lookupField)
        {
          if (http.readyState == 4)
          {
            result = http.responseText;
            var text;
            text = result.substring(6, 0);
            if(text !="沒有這個類型")
            {
              if ( -1 != result.search("null") )
                 {
              lookupField.style.borderColor = "red";
               fieldToFill.value = "";
              }
             else
             {
              lookupField.style.borderColor = "";
              fieldToFill.value = result;
                }
             }
            else
            {
                fieldToFill.value ="";
            }
           }
         }
        var codeField = null;
        function codechanged()
        {
         codeField = document.getElementById("codecode");
         var code = codeField.value;
         //code.length == 2?updateBooklist(code):code.length == 5?updateBook(code):"";
         if(code.length == 2)
         {
             updateBooklist(code);
         }
         else if(code.length == 5)
         {
             updateBook(code);
         }
         
        }
        function updateBooklist(code)
         {
         var booklistField = document.getElementById("booklist");
         ask("BookAjax.aspx?id="+code, booklistField, codeField);
        }
        function updateBook(code)
         {
         var bookField = document.getElementById("book");
         ask("BookAjax.aspx?id="+code, bookField, codeField);
        }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table width="300">
            <tr>
                <td style="width: 90px">
                    编号:</td>
                <td style="width: 187px">
                    <input id="codecode" type="text" οnkeyup="codechanged()" /></td>
             
            </tr>
            <tr>
                <td style="width: 90px">
                    分类:</td>
                <td style="width: 187px">
                    <input id="booklist" type="text"  /></td>
              
            </tr>
            <tr>
                <td style="width: 90px; height: 22px">
                    书名:</td>
                <td style="width: 187px; height: 22px">
                    <input id="book" type="text" /></td>
              
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>
 

 

BookAjax.aspx:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id"].Length == 2)
        {
            SelectCity("select leiming from biao1 where bianhao ="+Request["id"]);
        }
        else if (Request["id"].Length == 5)
        {
            SelectCity("select shuming from biao2 where ListBianhao =" + Request["id"]);
        }
    }
    public void SelectCity(string strSql)
    {
        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
        SqlCommand cmd = new SqlCommand(strSql);
        cmd.Connection = con;
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        da.SelectCommand = cmd;
        con.Open();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count !=0)
        {
            Response.Write(ds.Tables[0].Rows[0][0]);
        }
        else
        {
            Response.Write("沒有這個類型");
        }
        con.Close();

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值