为什么这个基本的 json 调用不起作用?
以下 JSON 调用总是会命中 AJAX 错误处理程序,我无法弄清楚为什么:
$.ajax({
type: "GET",
url: '<%= Url.Action("MyTest", "Detail") %>',
dataType: "json",
error: function (xhr, status, error) {
alert(xhr + " | " + status + " | " + error);
},
success: function (json) {
alert(json);
}
});
我得到的只是 无法加载资源:服务器响应状态为 500(内部服务器错误)http://localhost :4497/Detail/MyTest?_=1320681138394
当我在控制器中设置断点时,我可以看到它正在到达,所以我不确定请求落在哪里。这是 DetailController 中的操作:
Function MyTest() As JsonResult
Return Json("Hello")
End Function
有什么想法吗?
The following JSON call always hits the AJAX error handler, and I can't figure out why:
$.ajax({
type: "GET",
url: '<%= Url.Action("MyTest", "Detail") %>',
dataType: "json",
error: function (xhr, status, error) {
alert(xhr + " | " + status + " | " + error);
},
success: function (json) {
alert(json);
}
});
All I get is Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:4497/Detail/MyTest?_=1320681138394
When I set a breakpoint in the controller, I can see that it's being reached, so I'm not sure where the request is falling down. Here's the action in the DetailController:
Function MyTest() As JsonResult
Return Json("Hello")
End Function
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jQuery 错误处理程序被触发,因为它无法将返回的页面解析为有效的 JSON。由于您收到 500 内部服务器错误,因此该页面很可能不包含有效的 JSON。
在浏览器中加载此页面并修复它,直到它提供有效的 json:
在浏览器中提供有效的 json 后,尝试 jQuery ajax 调用。
我什至不知道 VB.NET 的基本功能,但是你可以让 http 上打印的唯一内容吗? ://localhost:4497/Detail/MyTest 就像:
如果页面输出的唯一内容是
{"message":"hello"}
那么 json 错误处理程序将不会触发The jQuery error handler is fired because it failed to parse the returned page as valid JSON. Since you get 500 internal server error, the page most likely doesn't contain valid JSON.
Load this page in your browser and fix it until it gives valid json:
After it is giving valid json in the browser, try the jQuery ajax call.
I have no idea of even the basic functionality of VB.NET but can you make so that the only thing that is printed on http://localhost:4497/Detail/MyTest is like:
If the only thing the page is outputting is
{"message":"hello"}
then json error handler will not fire