【问题标题】:http.post always entering error callback in IE8http.post 总是在 IE8 中输入错误回调
【发布时间】:2023-03-17 22:30:01
【问题描述】:

我有一个简单的 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 总是记录错误!!!

【问题讨论】:

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


    【解决方案1】:

    确保您点击的网址以正确的状态码 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);}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      • 2015-06-25
      • 2018-07-01
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多