0

默认3.aspx

这是我的第一页。其中我有两个文本框和一个提交按钮,onclick 提交按钮调用 Default4.aspx 页面,我已经编写了数据插入代码。

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js">
    </script>

    <script type="text/javascript">
$(function() {
$("#add").click(function() {

var login = $("#loginid").val();
var pass = $("#pass").val();
var dataString = 'login='+ login +'&pass='+pass;

$("#flash").show();
$("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle"> <span class="loading">Loading Comment...</span>');

$.ajax({
type: "POST",
url: "Default4.aspx",
data: dataString,
cache: false,
success: function(html){
$("#display").after(html);
//document.getElementById('content').value='';
//document.getElementById('content').focus();
$("#flash").hide();
}
});
 return false;
});
});
    </script>

</head>
<body>
    <form name="frm_add" id="frm_add">
    <input type="text" name="loginid" id="loginid" />
    <input type="text" name="pass" id="pass" />
    <input type="submit" id="add" value="Submit" />
    <div id="flash"></div>
<div id="display"></div>
    </form>
</body>
</html>

Default4.aspx

<%@ Import Namespace="System.Data.SqlClient" %>

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <%
    Dim login, pass As String
        login = Request.QueryString("login")
        pass = Request.QueryString("pass")
        Dim cs As String = ConfigurationManager.ConnectionStrings("eExamSolutionConnection").ConnectionString
        Dim cn As New SqlConnection(cs)
        Dim cmd As New SqlCommand
        ' MsgBox(dob)
        cmd.CommandText = "INSERT INTO ADMIN_CREDENTIAL VALUES ('" & login & "','" & pass & "')"
        cmd.Connection = cn
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
        cmd.Dispose()
        cn.Dispose()
        Response.Write("Added")
     %>
</body>
</html>

但是,每当我提交值时,都会在我的表中插入空白行。需要帮忙 !!

4

2 回答 2

3

使用Fiddler并检查是否一切正常。

JQuery Ajax的TYPE更改为,看看它是否有效。GET

$.ajax({
type: "GET",
url: "Default4.aspx",
data: dataString,
cache: false,
success: function(html){
$("#display").after(html);
//document.getElementById('content').value='';
//document.getElementById('content').focus();
$("#flash").hide();
于 2012-07-24T11:31:44.477 回答
1

尝试更改您发布的数据

data: {login: $("#loginid").val(), pass: $("#pass").val()},

然后,在您的 Default4.aspx 上,从表单数据中获取数据,而不是从查询字符串中获取数据。Request.Form("login")Request.Form("pass")

于 2012-07-24T11:38:08.290 回答