我在一个 html(使用 xmlHttp.responseText)页面中创建了一个 javascript,我在该页面中从一个查询数据库(MSSQL)中用户名的用户编号的 aspx 页面请求一个值。当我加载 html (IE8) 时,我得到了这个“未知的运行时错误行:30”。应该是什么导致了问题?需要帮忙。这是我的代码:
这是 HTML 页面和 Javascript:
<!DOCTYPE html> <html> <head> <script type="text/javascript"> function showUsernum(str) { var xmlHttp; if (str=="") { document.getElementById("textExists").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) { //alert(str); document.getElementById("textExists").innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET","http://localhost/Base_Data/default.aspx?q="+str,true); xmlHttp.send(); } </script> </head> <body> <form action="" method="post"> <label>UserName <input type="text" name="textUser" id="textUser" onchange="showUsernum(this.value)"> </label> </form> <br/> <div > <form name="form1" method="post" action=""> <label> <div id="textExists">Exists?</div> </label> </form> </div> </body>
这是我的 ASP 代码。
protected void Page_Load(object sender, EventArgs e) { Response.Expires = -1; SqlConnection conn; string connection = ConfigurationManager.ConnectionStrings ["BaseData"].ConnectionString; conn = new SqlConnection(connection); string sql = "SELECT USERNUM FROM useraccount WHERE USERNAME ='" + Request.QueryString["q"] + "'"; SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); string contNm = Convert.ToString(cmd.ExecuteScalar()); Response.Write("textExists=" + contNm ); conn.Close(); }
真的很感激任何回应。谢谢你。