Ajax调用WebMethod没有任何反应
本文关键字:任何反 调用 WebMethod Ajax | 更新日期: 2023-09-27 18:35:04
为什么哦,为什么这段代码不做任何事情?!我的 ajax 有什么问题?我的阿贾克斯:
$.ajax({
type: "POST",
url: "/index.aspx/Uppdatera",
data: "{ Id:"+ JSON.stringify($item.Id) +" }",
error:
alert("error")
});
我的 C#:
[WebMethod(EnableSession = true)]
public static void Uppdatera(object id)
{
id.ToString();
using (StreamWriter s = new StreamWriter("C:/Users/robert/Documents/visual studio 2013/Projects/GolvProjektet/GolvProjektet/hej.txt"))
{
s.Write("hej" + id);
}
}
在 ajax 调用中添加 contentType y dataType:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "/index.aspx/Uppdatera",
data: "{ Id:"+ JSON.stringify($item.Id) +" }",
error:
alert("error")
});