Gre*_*reg 5 internet-explorer json angularjs 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");
});
Run Code Online (Sandbox Code Playgroud)
这是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");
})
Run Code Online (Sandbox Code Playgroud)
这是我目前所知道的:
在您的 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);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4148 次 |
| 最近记录: |