http.post总是在IE8中输入错误回调

时间:2015-07-13 12:08:49

标签: javascript angularjs internet-explorer-8 ie-developer-tools angular-http

我有一个简单的Angular服务,可以在FireFox,Safari,Chrome和IE9 +中正常工作

但是,对于IE8,该服务始终处于.error回调。

JS:

myService.authUser($scope.data)
    .success(function(data, status, headers, config) {
        console.log("Success..");
        $scope.showProfile = true;
    })
    .error(function (data, status, headers, config) {
        console.log("ERRROR!!!");
        $scope.errorText = true;
    })

app.service('myService', function($http) {


    this.authUser = function (myData) {
        return $http({
            url: 'url',
            method: "POST",
            data: angular.toJson(myData),
            headers: {
                'Content-Type': 'application/json'
            }
        });
    };
});

在上面的场景中,IE8总是记录ERRROR !!!

1 个答案:

答案 0 :(得分:0)

确保您所点击的网址响应正确的状态代码EG:200,404等

例如,如果您的后端是.NET MVC

public ActionResult TestError(string id) // id = error code{
Response.StatusCode = 400; // Replace .AddHeader
var error = new Error();  // Create class Error() w/ prop
error.ErrorID = 123;
error.Level = 2;
error.Message = "You broke the Internet!";

return Json(error, JsonRequestBehavior.AllowGet);}
相关问题