Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript xmlHttp.responseText未知错误定义_Javascript_Asp.net_Sql_Sql Server_Xmlhttprequest - Fatal编程技术网

Javascript xmlHttp.responseText未知错误定义

Javascript xmlHttp.responseText未知错误定义,javascript,asp.net,sql,sql-server,xmlhttprequest,Javascript,Asp.net,Sql,Sql Server,Xmlhttprequest,我已经在一个html(使用xmlHttp.responseText)页面中创建了一个javascript,我正在从一个aspx页面请求一个值,该页面查询数据库(MSSQL)中用户名的用户号。当我加载html(IE8)时,我得到了这个“未知运行时错误行:30”。是什么导致了这个问题?我需要帮助。这是我的密码: 以下是HTML页面和Javascript: <!DOCTYPE html> <html> <head> <script ty

我已经在一个html(使用xmlHttp.responseText)页面中创建了一个javascript,我正在从一个aspx页面请求一个值,该页面查询数据库(MSSQL)中用户名的用户号。当我加载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>
    

  • 非常感谢您的回复。谢谢。

    问题是您试图将整个页面(包括
    标记和所有内容)分配到单个DOM元素中,IE并不喜欢这样

    要让服务器只发送原始HTML而不发送整个文档,您需要清除响应。此外,您没有正确处理数据库对象,并且会受到SQL注入攻击,因此优化的代码将是:

    string connection=ConfigurationManager.ConnectionStrings[“BaseData”]。ConnectionString;
    使用(SqlConnection conn=newsqlconnection(连接))
    {
    conn.Open();
    string sql=“从useraccount中选择USERNUM,其中USERNAME=@user”;
    字符串contNm=“”;
    使用(SqlCommand cmd=newsqlcommand(sql,conn))
    {
    cmd.Parameters.AddWithValue(“@user”,Request.QueryString[“q”]);
    contNm=Convert.ToString(cmd.ExecuteScalar());
    }
    Response.Clear();
    Response.Write(“textExists=“+contNm”);
    Response.End();
    康涅狄格州关闭();
    }
    
    尝试添加
    Response.Clear()Response.Write()和
    Response.End()之前的code>之后。嗨,阴影向导,这对我有用,谢谢!但是我有一个问题,我的html页面是否有可能在调用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();
    
      }