Default3.aspx
This is my first page. in which i have two textbox and one submit button, onclick of submit button calling Default4.aspx page, where i have written the data insertion code.
<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>
But, blank row inserted into my table, whenever i’m submitting the value. Need help !!
Use Fiddler and check if everything is alright.
Change the TYPE of JQuery Ajax to
GETand see if it works or not.