Ajax数据绑定..? [英] Ajax Data Binding ..?

查看:61
本文介绍了Ajax数据绑定..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与SqlServer的Ajax数据绑定.我正在尝试从sqlserver检索数据,但是此代码中出现错误.
错误是...

Ajax data binding with SqlServer. I am trying to retrieve data from sqlserver but I''m getting an error in this code.
Error is ...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head><body>    <form method="post" action="Data.aspx?q=manoj" id="form1"><div class="aspNetHidden"><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTI2NTY4ODI3MWRkFbiJkgowu+T1QXVGsmTwAhctwfd1Q5UtHcRyxNwZQOA=" /></div><div class="aspNetHidden">	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgL874/EDAKM54rGBgJSPacj24MwGNzCI7lqM5q+15a8e8SgxfGCGx7QCBad" /></div>    <div>       </div>    <span id="Label1">Label</span>    <input type="submit" name="Button1" value="Button" id="Button1" /> </form></body></html>    


This is value  of  textbox  after  ecode  Exducation




Java脚本代码




java script code

<script type="text/javascript">
    function showCustomer(str) {
        if (str == "") {
            document.getElementById("txtHint").innerHTML = "";
            return;
        }
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("Label1").value = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","Data.aspx.cs?q=" + str, true);
        xmlhttp.send();
    }
</script>




Data.aspx.cs包含sql的所有代码

ASP代码




Data.aspx.cs contains all code for sql

Asp code

<pr><div id="txtHint">Customer info will be listed here...</div>
    <input type ="text" id="Label1" />
    <select name="customers" onchange="showCustomer(this.value)">
         <option value="">Select a customer:</option>
         <option value="A">Alfreds Futterkiste</option>
         <option value="B">North/South</option>

     </select></pr>





Data.Aspx.cs代码....





Data.Aspx.cs Code ....

string eid = Request.QueryString["q"];
        string con = " Data Source= mk-pc; initial catalog=data;       integrated security = true";
           string query = "Select *From Employee where ename= ''" + eid + "''";
           SqlConnection cn = new SqlConnection(con);
           SqlCommand cmd = new SqlCommand(query, cn);
           cn.Open();
           cmd.ExecuteNonQuery();

推荐答案

尽管您没有告诉您什么错误,但我在这里确实看到了一个问题:
Though you have not told what error, I do see an issue here:
xmlhttp.open("GET","Data.aspx.cs?q=" + str, true);



将此行更改为:



Change this line to:

xmlhttp.open("GET","Data.aspx?q=" + str, true);


您无需在页面名称中写入 .cs .它将自动与该文件对话.


You don''t need to write .cs in the page name. It would automatically talk to that file.


这篇关于Ajax数据绑定..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆