Every time I try to call the Ajax web method, I keep receiving a 'save error' message. However, the data is successfully saved to the database without any issues. I have checked for errors but couldn't find any. How can I display an alert saying 'Saved' after the operation?
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json",
url: "paygrade.aspx/SavePayGrade",
data: JSON.stringify({ value: rec, arr: arr }),
success: function (msg) {
console.log(msg.d);
alert(msg.d);
},
error: function (msg) {
alert("Save error");
}
});
[WebMethod]
public static string SavePayGrade(string value, params string[] arr)
{
string res = "";
using (FlairEntities context = new FlairEntities())
{
tblPayGrade obj = new tblPayGrade();
obj.salaryGrade = arr[0];
obj.salary = arr[1];
obj.note = arr[2];
context.tblPayGrades.Add(obj);
context.SaveChanges();
res = "Saved";
}
return res;
}