当我使用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");
})
这是我目前所知道的:
答案 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并参考知识库文章中的文件信息。