当 Angulars $http.post 与 large/complex json 数据集一起使用时,Internet Explorer 11 崩溃

Internet Explorer 11 crashes when Angulars $http.post is used with large/complex json datasets

当我使用 Angulars $http.post 方法 post large/complex json 对象时,我始终能够使 IE11 崩溃。

我已经在 IE11 中设置了一个 angular 示例,可以是 运行 以查看我遇到的行为:http://plnkr.co/edit/yYaDy8d00VGV6WcjaUu3?p=preview

这是导致崩溃的代码:

$http.post($scope.saveDocumentUrl, { "document": doc, "submit": submit, "trash": trash }).success(function (data) {
            if (!data.Success) {
                bootbox.alert(data.Message);
            } else {
                if (trash) {
                    $scope.periodReviewDocuments.pop(doc);
                    hideModalWindow(); //we call this in the event that the method was called from the document and not from the list.
                }

                if(submit){
                    $scope.periodReviewDocuments.pop(doc);
                    resetForm();
                    bootbox.alert("Your document has been submitted");
                    hideModalWindow();                        
                }

            }
            $scope.isBusy = false;
        }).error(function (data, status) {
            $scope.isBusy = false;
            bootbox.alert("The server encountered an error and could not save your document. If this problem persists please contact the administrators");
        });

这是 jquery 工作代码:

    $.ajax({
            url: $scope.saveDocumentUrl,
            data: JSON.stringify({ "document": doc, "submit": submit, "trash": trash }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            type: "POST"
        }).done(function (data) {
            if (!data.Success) {
                bootbox.alert(data.Message);
            } else {
                if (trash) {
                    $scope.periodReviewDocuments.pop(doc);
                    hideModalWindow(); //we call this in the event that the method was called from the document and not from the list.
                }

                if (submit) {
                    $scope.periodReviewDocuments.pop(doc);
                    resetForm();
                    bootbox.alert("Your document has been submitted");
                    hideModalWindow();
                }

            }
            $scope.isBusy = false;
        }).fail(function (data, status) {
                $scope.isBusy = false;
                bootbox.alert("The server encountered an error and could not save your document. If this problem persists please contact the administrators");
        })

这是我目前所知道的:

  1. 此问题仅发生在 IE11 - Windows 8.1 / IE 11 (11.0.9600.17498) 中。更新版本 11.0.15 (KB3008923)。
  2. 发送请求后浏览器崩溃。
  3. 我已经检查了服务器端传入的请求,有效载荷已经 serialised/deserialised 完美。
  4. 我用 jquery $.ajax 替换了 $http.post 函数并解决了问题,但这不是解决方案,因为我正在使用 angular .
  5. 我在这个问题上浪费了 3 天时间

在您的 Internet Explorer 版本中,使用翻译过滤器调用 JSON.stringify 会使 IE 崩溃以处理大型数据集。

这里的技巧是在传递给 $http.post

之前自己将对象字符串化

http://plnkr.co/edit/PbMxMY?p=preview

  var body = {"document" .....

  var jsonData = JSON.stringify(body);

  $http.post("/test", jsonData).then(function(response) {
    console.log(response.data);
  });

  $interval(function() {
    $rootScope.tick = Date.now();
  }, 500);
});

已在本月的 IE 更新中修复,可能由 https://support.microsoft.com/en-us/kb/3075516

附带说明一下,您可以使用 JavaScript 中的 ScriptEngineBuildVersion 检测到这一点。确保您还使用了 ScriptEngineMajorVersion 和 ScriptEngineMinorVersion 并参考知识库文章中的文件信息。