当Angulars $ http.post与大型/复杂json数据集一起使用时,Internet Explorer 11崩溃

时间:2015-01-23 16:49:55

标签: json angularjs internet-explorer internet-explorer-11

当我使用Angulars $ http.post方法发布大型/复杂的json对象时,我始终能够崩溃IE11。

我已经设置了一个角度示例,可以在IE11中运行以查看我遇到的行为: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. 我检查了服务器端的传入请求,并且已完全序列化/反序列化了有效负载。
  4. 我用jquery $ .ajax替换了$ http.post函数,它解决了这个问题,但这不是解决方案,因为我使用的是角度。
  5. 我在这个问题上已经失去了3天

2 个答案:

答案 0 :(得分:3)

在您的Internet Explorer版本中,使用转换过滤器调用JSON.stringify会导致大型数据集崩溃。

这里的技巧是在传递给$ 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);
});

答案 1 :(得分:0)

修正了本月的IE更新,可能是https://support.microsoft.com/en-us/kb/3075516

作为旁注,您可以通过在JavaScript中使用ScriptEngineBuildVersion来检测这一点。确保您还使用ScriptEngineMajorVersion和ScriptEngineMinorVersion并参考知识库文章中的文件信息。