In angular $http service, How can I catch the “status” of error?

前端 未结 6 2043
南笙
南笙 2020-12-08 04:40

I\'m reading a book called, \"Pro Angular JS\". However, I have a question about how to catch a status of error.

What I coded is :

$http.get(dataUrl)         


        
6条回答
  •  醉梦人生
    2020-12-08 04:45

    From the official angular documentation

    // Simple GET request example :
    $http.get('/someUrl').
      success(function(data, status, headers, config) {
        // this callback will be called asynchronously
        // when the response is available
      }).
      error(function(data, status, headers, config) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
      });
    

    As you can see first parameter for error callback is data an status is second.

提交回复
热议问题