angularjs - How to add header in to $http.post -
this question has answer here:
- angular js - set token on header default 2 answers
i have below piece of code used bootstrap typeahead.
return $http.post(searchclients, { params: { clientname: val, } }).then(function(response){ return response.data.results; });
i need add token header. how go adding token header?
searchclients holds url defined elsewhere. code works, need know on how info in header.
$http({ method: 'post', headers: { 'content-type': 'application/json;charset=utf-8', 'x-token': '9af4e2526279434180c7365ef86f6e77' }, url: 'http://xxx/user/validate?username='+username+'&password='+password+, data: {username:username, password:password} }).then(function successcallback(response) { console.log(response); var logininfo = (response); localstorage.setitem("user_info", json.stringify(logininfo)); $state.go('home'); }, function errorcallback(response) { console.log(response) if(response.status = 401){ // $scope.showpopup1("message","invaild username && password"); } });
Comments
Post a Comment