简单的 AJAX 不起作用
我有这个 AJAX 代码,但它似乎没有抛出“警报”方法。相反,什么也没有发生。我用 Fiddler 查看了它并收到以下错误消息: {"Message":"处理请求时出错。","StackTrace":"","ExceptionType":""}
我正在尝试在代码中调用 Web 方法-后面调用了 MyWebMethod
:
$.ajax({ type: "POST",
url: "Test.aspx/MyWebMethod",
data: "{" + username + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function() {
alert("success");
},
fail: function() {
alert("Fail");
}
});
当页面上有脚本管理器时,Web 方法工作正常,但我想删除脚本管理器,并认为使用 AJAX 将是最好的方法。
谢谢
I have this AJAX code, but it doesn't seem to throw the 'alert' method. Instead, nothing happens. I looked at it with Fiddler and got this error message:{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}
I'm trying to call a web method in the code-behind called MyWebMethod
:
$.ajax({ type: "POST",
url: "Test.aspx/MyWebMethod",
data: "{" + username + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function() {
alert("success");
},
fail: function() {
alert("Fail");
}
});
The web method worked fine when I had a script manager on the page, but I want to remove the script manager and thought that using AJAX would be the best way.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在 web.config 中启用了自定义错误。因此,返回的异常将是通用的(大部分为空白)并且每次都相同。这使得调试变得困难。
要查看真正的异常,请暂时禁用自定义错误。 以下是仅针对 Web 服务执行此操作的方法(如果您需要)那种粒度。
You have custom errors enabled in the web.config. Therefore, the exception returned will be generic (mostly blank) and the same every time. This makes it difficult to debug.
To see the real exception, temporarily disable custom errors. Here is how to do that for web services only, if you need that granularity.
我认为如果您将
fail
更改为error
,您将收到第二个警报框。[编辑]我认为,如果您随后更改
为,
您将收到第一个警报,尽管在没有看到您所调用的服务的情况下很难知道这一点。
I think if you change
fail
toerror
, you'll get the second alert box.[Edit] I think if you then change
to
you'll get the first alert, although it's hard to know that without seeing the service you're calling.