[英]alert message not working properly in Ajax web method
Always getting the 'save error' message when I call the Ajax web method.But I can save the data to database.I couldn't find any errors.How can I get alert 'Saved' . 当我调用Ajax Web方法时总是收到“保存错误”消息。但是我可以将数据保存到数据库中。我找不到任何错误。如何获得警报“已保存”。 my web method is
我的网络方法是
$.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;
}
try following 尝试跟随
console.log(msg);
alert(msg);
As you are sending response in string( return res; ), you cant use msg.d You need to use only msg . 当您以字符串形式发送响应( return res; )时,您不能使用msg.d您只需要使用msg 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.