【问题标题】:MiniProfiler Throwing Unexpected Token with Ajax.BeginFormMiniProfiler 使用 Ajax.BeginForm 抛出意外的令牌
【发布时间】:2013-12-21 02:53:36
【问题描述】:

我在 MVC 4 应用程序上使用 MiniProfiler。我们有一个以模式呈现的视图(使用 Colorbox jquery 插件)。然后,该视图中有一个部分视图,其中包含如下所示的 ajax 表单:

@using(Ajax.BeginForm("<action name>", "<controller name>", new {area="<area name>"}, new AjaxOptions
    {
        UpdateTargetId = "modal-body",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "POST"
    }))
{
    <html for form here>
}

当我们提交表单时,它会返回相同的部分视图以覆盖视图上的整个部分。发布时 MiniProfiler 会抛出错误: SyntaxError: Unexpected token ,

这发生在这个函数中:

var jQueryAjaxComplete = function (e, xhr, settings) {
            if (xhr) {
                // should be an array of strings, e.g. ["008c4813-9bd7-443d-9376-9441ec4d6a8c","16ff377b-8b9c-4c20-a7b5-97cd9fa7eea7"]
                var stringIds = xhr.getResponseHeader('X-MiniProfiler-Ids');
                if (stringIds) {
                    var ids = typeof JSON != 'undefined' ? JSON.parse(stringIds) : eval(stringIds);
                    fetchResults(ids);
                }
            }
        };

它需要一个 json 的 guid 数组,但它却是两次获取该数组,如下所示:

"["6de0e02c-e694-4d8a-ac22-ea6a847efe0e","970f6640-fe5b-45d9-bf59-c916b665458d"], ["6de0e02c-e694-4d8a-ac22-ea6a847efe0e","970f6640-fe5-b bf59-c916b665458d"]"

这会导致它在尝试解析数组时呕吐。我不确定为什么数组会重复。任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 您在浏览器的开发者工具中看到了什么...来自服务器的响应反映了这些意外结果还是看起来正确?
  • miniprofiler 函数中的注释说它应该是这样的: ["008c4813-9bd7-443d-9376-9441ec4d6a8c","16ff377b-8b9c-4c20-a7b5-97cd9fa7eea7"] 但在我的情况下得到 "["6de0e02c-e694-4d8a-ac22-ea6a847efe0e","970f6640-fe5b-45d9-bf59-c916b665458d"], ["6de0e02c-e694-4d8a-ac22-ea6a847efe0e","970f6640-fe5b-d"] c916b665458d"]"
  • 我对 MiniProfiler 不太了解,但那里有可能相关的错误。code.google.com/p/mvc-mini-profiler/issues/detail?id=99

标签: ajax mvc-mini-profiler


【解决方案1】:

这是一个 miniprofiler 错误 https://github.com/MiniProfiler/ui/pull/5

等待下次更新。

【讨论】:

    猜你喜欢
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 2012-02-10
    • 2015-05-21
    • 2019-08-09
    相关资源
    最近更新 更多