AngularJS $http error function never called

后端 未结 5 1027
陌清茗
陌清茗 2020-12-09 03:22

I have that simple code :

$http.get(\"/api/test\")
    .success(function (data, status, headers, config) {
        console.log(data);
        return data;
           


        
5条回答
  •  既然无缘
    2020-12-09 04:09

    If you are using AngularJS version 1.1.1 or greater...

    Does appending '.json' work?:

    $http.get("/api/test.json")
      .success(function (data, status, headers, config) {
          console.log(data);
          return data;
      }).error(function (data, status, headers, config) {
          alert("error");
          return status;
    });
    

    If so, it can also be fixed with:

    myModule.config(['$httpProvider', function ($httpProvider) {
      $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
    }]);
    

    See this => Angular JS Fails After Upgrade from 1.1.0 to 1.1.1

提交回复
热议问题