Hi,
In my application iam using jquery with webservice method for inserting to a table.
problem is records insertng correctly. but iam not getting response message from webservice.
this is the code
$(document).ready(function(){
$('#btnsave').click(function(){
var id=$('#txtid').val();
var fname=$('#txtfname').val();
var lname=$('#txtlname').val();
//alert(id);
//alert(fname);
$.ajax({
type: "POST",
url: "Dataprocess.asmx/insert",
data: "{'id': '" + id + "','fname': '"+fname+"','lname':'"+lname+"'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
if(msg=="Success")
{
$('#disp').css("color","green").html("Update successfully");
}
else
{
$('#disp').css("color","red").html("Error ckeck data");
}
},
error: function(xhr, status, error) {
alert('An error occurred: ' + xhr);
}
});
});
});
********************************************************
[WebMethod]
public string insert(string id, string fname, string lname)
{
SqlConnection con = new SqlConnection("Data Source=BAIJU-PC;Initial Catalog=Baiju;Integrated Security=True");
SqlCommand cmd = new SqlCommand("insert into emp values('" + id + "','" + fname + "','" + lname + "')", con);
string msg = "";
try
{
con.Open();
cmd.ExecuteNonQuery();
msg = "Success";
return msg;
}
catch (Exception ex)
{
msg = ex.Message;
return msg;
}
finally
{
con.Close();
cmd.Dispose();
}
}
how to solve this
Regards
Baiju