【问题标题】:Uncaught SyntaxError: Unexpected token < Using jqgrid and MVC 4Uncaught SyntaxError: Unexpected token < Using jqgrid and MVC 4
【发布时间】:2013-10-24 13:16:13
【问题描述】:

提交不正确的数据时,JQGrid 不会在表单中显示错误。 它适用于我的本地机器,但不适用于生产。它曾经在 prod 中工作,但在过去的几个月里我做了一些更改,但不确定是哪个更改破坏了它。 我正在使用 JQGrid 4.4.1、jquery 1.7.2 和 MVC 4。浏览器中的错误显示如下

Uncaught SyntaxError: Unexpected token < jquery%20-1.7.2.min.js:3
e.extend.parseJSON jquery%20-1.7.2.min.js:3
editItems.errorTextFormat WaterReadingCapture:1291
$.extend.complete jquery.jqGrid.src.js:7572
o jquery%20-1.7.2.min.js:3
p.fireWith jquery%20-1.7.2.min.js:3
w jquery%20-1.7.2.min.js:10
d jquery%20-1.7.2.min.js:10

编辑

这是我从服务器得到的。 正文中包含此内容的 Html 页面。我还升级了 RazorEngine。问题可能出在服务器上,与 jquery 和 jqgrid 无关吗?但是我从 prod 复制了整个站点并在我的本地计算机上运行它并且它有效。

<h2>500 - Internal server error.</h2>
  <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>

WaterReadingCapture

 errorTextFormat: function (data) {
                      return '<span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>' +
                     "<strong>" + $.parseJSON(data.responseText).Message + "<strong>";
                   },

JQGrid

if(Status != "success") {
    ret[0] = false;
    ret[1] = $($t).triggerHandler("jqGridAddEditErrorTextFormat", [data, frmoper]);
    if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
        ret[1] = rp_g
    e[$t.p.id].errorTextFormat.call($t, data);
    } else {
        ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status; // line of error
    }

} 否则 {

编辑 我恢复了 6 个月前的备份,但它仍然给出同样的错误,我知道它当时有效。因此 IIS 或服务器中的某些内容发生了变化。感谢您的帮助

【问题讨论】:

  • 一个错误很好,但没有看到产生它的代码我们无能为力。
  • 请发布源文件WaterReadingCapture:1291jquery.jqGrid.src.js:7572的摘录。

标签: jquery asp.net-mvc-4 jqgrid


【解决方案1】:

我认为问题在于您使用的errorTextFormat 的实现。 data 参数是jqXHR 对象,它是XMLHTTPRequest 对象的超集。两者都支持getResponseHeader 方法,您可以使用该方法来检测来自服务器的响应是包含 JSON 数据还是 HTML 数据。所以你可以测试类似的东西

errorTextFormat: function (data) {
    var contentType = xhr.getResponseHeader("Content-Type");
    if (typeof contentType === string &&
            contentType.split(";")[0] === "application/json") {
        // you can use $.parseJSON(data.responseText) here
        return '<span class="ui-icon ui-icon-alert" ' +
           'style="float: left; margin-right: .3em;"></span>' +
           "<strong>" + $.parseJSON(data.responseText).Message + "<strong>";
    }
    return data.responseText;
}

我使用了contentType.split(";")[0],因为“Content-Type”标头可以是"application/json; charset=utf-8""application/json"

【讨论】:

  • 我现在收到了回复,但现在在对话框中显示了一个 html 页面,上面写着“500 - 内部服务器错误”。这可能与什么有关?它在我的本地机器和我们使用的开发盒上运行良好。这曾经工作过。我将在 prod 上创建一个测试站点,并恢复和恢复最新的备份,然后继续我的工作。感谢您的帮助
【解决方案2】:

很久以前就修复了这个问题。问题是 IIS 没有发送详细的错误。不要不知道选项如何从详细错误更改为本地请求的详细错误和 IIS 中错误页面模块上远程请求的自定义错误页面。将其改回详细错误并从此开始工作。

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-13
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 2019-02-10
    • 2014-07-08
    • 2011-03-09
    相关资源
    最近更新 更多