$http response header message

老子叫甜甜 提交于 2019-12-11 09:27:27

问题


is it possible in anulgarjs to fetch the response header message?

in a code similar to that

$http.get(url)
    .success(){
         something
    }.error(status,"headers text message)"{
             alert(status+" "+"headers text message or a method to get it";
    }

in the alert i need to write somthing like that: 500 internal server error. In the console log i can see the error status and text message, what do i have to put in the error case? what is the best way to do that?


回答1:


try this

$http.get(url)
    .then(function(response) {
  var data = response.data;
  var status = response.status;
  alert(status);
});

See this document




回答2:


Of course you can! On success (or error) you have a callback with this parameters

$http({
url: 'url',
method: 'GET'
}).success(function(data, status, headers, config){
});

Check the documentation http://docs.angularjs.org/api/ng/service/$http



来源:https://stackoverflow.com/questions/22038761/http-response-header-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!