WebMethod 未被调用
我通过 jquery.ajax 将包含字符串的 javascript 变量传递到服务器。尽管调用了“成功”条件,但从未调用服务器端 WebMethod。客户端:
$.ajax({
type: "post",
url: "Playground.aspx/childBind",
data: {sendData: ID},
//contentType: "application/json; charset=utf-8",
dataType: "text",
success: function (result) { alert("successful!" + result.d); }
})
服务器:
[WebMethod]
public static string childBind(string sendData)
{
return String.Format("Hello");
}
I am passing a javascript variable containing a string to the server via jquery.ajax. Although the "success" condition is called, the server-side WebMethod is never called. Client:
$.ajax({
type: "post",
url: "Playground.aspx/childBind",
data: {sendData: ID},
//contentType: "application/json; charset=utf-8",
dataType: "text",
success: function (result) { alert("successful!" + result.d); }
})
Server:
[WebMethod]
public static string childBind(string sendData)
{
return String.Format("Hello");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请尝试对您的 Ajax 请求进行以下修复:
注意将
dataType
和data
值更改为字符串。Try following fixes for your Ajax request:
Notice changed
dataType
anddata
value as a string.我遇到了同样的问题。经过谷歌搜索后,我找到了解决方案,它对我有用。导航到 RouteConfig.cs 并注释掉以下行:
I have encountered the same issue. After Googling, I found the solution, and it works for me. Navigate to RouteConfig.cs and comment out the line below:
我想添加一个注释:您的“ID”(或另一个字段)字符串将出现数据错误,其中包含像 = ' 这样的引号。
解决这个问题:
i would want to add one note: you will have data error of your "ID" (or another field) string contains quotes like = '.
solve this issue:
尝试这样:
JQuery:
ASPX.CS:
Try like this:
JQuery:
ASPX.CS: