为什么这个基本的 json 调用不起作用?

发布于 2024-12-14 06:28:41 字数 632 浏览 3 评论 0原文

以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-12-21 06:28:41

jQuery 错误处理程序被触发,因为它无法将返回的页面解析为有效的 JSON。由于您收到 500 内部服务器错误,因此该页面很可能不包含有效的 JSON。

在浏览器中加载此页面并修复它,直到它提供有效的 json:

http://localhost:4497/Detail/MyTest

在浏览器中提供有效的 json 后,尝试 jQuery ajax 调用。

我什至不知道 VB.NET 的基本功能,但是你可以让 http 上打印的唯一内容吗? ://localhost:4497/Detail/MyTest 就像:

print( '{"message":"hello"}' );

如果页面输出的唯一内容是 {"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:

http://localhost:4497/Detail/MyTest

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:

print( '{"message":"hello"}' );

If the only thing the page is outputting is {"message":"hello"} then json error handler will not fire

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文