I m a student and I m working with ajax.
I want to search the record but my ajax call logic is wrong??
I fetch the record from the database using ajax successfully but search functionality using ajax but I think my ajax call is wrong?
Database field:
table name: tblstud
studid int pk auto increment,
studname varchar(50),
studaddress varchar(50),
procedure for getdatalist:
ALTER PROCEDURE [dbo].[selectstud]
AS
BEGIN
select * from tblstud;
END
Emploee.aspx
<body><form id="form1" runat="server"><div><table><tr><td>StudentName:</td><td><asp:TextBox ID="txtname" runat="server"></asp:TextBox></td></tr><tr><td>StudentAddress:</td><td><asp:TextBox ID="txtaddress" runat="server"></asp:TextBox></td></tr><tr><td><input type="button" id="btnsave" value="Submit" onclick="saverecord()" /></td></tr><tr><td>
Search Record: <asp:TextBox ID="txtsearch" runat="server"></asp:TextBox><input id="btnsearch" type="button" value="Search" onclick="searchrecord()" /></td></tr></table></div><div class="row"><div><table id="tbl" border="1"><thead><tr><th>StudentName</th><th>StudentAddress</th"><br /><br /><th>Edit</th></tr></thead></table></div></div><script type="text/javascript">$(document).ready(function () {
GetData();
});
function searchrecord(studname) { //here is an problem with search record??
if ($("#btnsearch").val() == "Search") {
debugger$.ajax({
type: "POST",
url: "Emploee.aspx/search",
data: "{ studname:'" + $("#txtsearch").val() + "' }",
contentType: "application/json",
success: function (data) {
debugger$("#txtsearch").val(data.d);
},
});
}
}
//for getdatalist
function GetData() {
$.ajax({
url: 'Emploee.aspx/GetData',
type: 'post',
contentType: 'application/json;charset=utf-8',
datatype: 'json',
success: function (data) {
data = JSON.parse(data.d);
$.each(data, function (index, element) {$("#tbl").append('<td>' + element.studname + '</td>');$("#tbl").append('<td>' + element.studaddress + '</td>');
});
},
error: function (error) {
alert('Not Get Data')
},
});
}</script></form></body>Emploee.aspx.cs
[WebMethod] //for retrieve the data
public static string GetData()
{
cn.Open();
string data = "";
SqlCommand cmd = new SqlCommand("selectstud", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
data = JsonConvert.SerializeObject(ds.Tables[0]);
}
cn.Close();
return data;
}
[WebMethod]
public static void search(string studname)
{
cn.Open();
SqlCommand cmd = new SqlCommand("SELECT studname FROM tblstud WHERE studname LIKE '%'+@studname+'%'", cn);
cmd.Parameters.AddWithValue("@studname", studname);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine("{1}",reader.GetString(1));
}
}
else
{
Console.WriteLine("No rows found.");
}
reader.Close();
}

see my browser log which place I m going to wrong?
which place I m not correct?plz, help?