hello i have a litel problem i try to call a function in c# throw ajax but it dosen’t work i try evrey thing but still nothing can some one plz tell me what’s wrong
function Save(ID, FullId) {
var code ="1234"// prompt("הכנס סיסמא", "סיסמא");
var flag = 2;//subcatgory
var catname='';
if (code == "1234") {
if (FullId == "tdcatid" + ID){
flag = 1; //catgory
}
catname=$('#'+FullId).val();
$.ajax({
async: false,
type: "POST",
url: "admins.aspx/SaveCondition",
data: '{catId: ' + ID + ',catFlag:' + flag + ',catName: ' + catname + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
}
});
sever side
[System.Web.Services.WebMethod]
public static int SaveCondition(int catId, int catFlag, string catName)
{
int answer=(int) Dbhelper.ExecuteScalar("server=MY_COMP\\AMIT;database=IDEAS;Trusted_Connection=True",
"sp_save_catgory_and_sub",
new SqlParameter("@caname", catName),
new SqlParameter("@catid", catId),
new SqlParameter("@flag", catFlag)
);
return answer;
}
I think you may be missing some quotes around your data parameters and the framework cannot deserialize the json object correctly (ie. to the types on your signature):
(you just really need them around the string parameter catname…)
also, it may be that you pasted just part of your code, but you’re missing closing brackets at the and (2)