angularjs - Change Accept-Language Header with javascript - Stack Overflow

My API uses the Accept-Language header to get it's current language which returns the json transla

My API uses the Accept-Language header to get it's current language which returns the json translated. Never mind that.

How can i change the header with angularJS/Javasctipt. I tried this:

  $http.defaults.headers.post["Accept-Language"] = "bs-Latn-BA";

but it doesn't seem to work, are there any other alternatives?

My API uses the Accept-Language header to get it's current language which returns the json translated. Never mind that.

How can i change the header with angularJS/Javasctipt. I tried this:

  $http.defaults.headers.post["Accept-Language"] = "bs-Latn-BA";

but it doesn't seem to work, are there any other alternatives?

Share Improve this question asked Jul 15, 2015 at 8:24 AlCodeAlCode 5651 gold badge8 silver badges23 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

The default headers sent for every single request live in the $httpProvider.defaults.headers.mon object.

You can change or augment these headers using the .config() function for every request, like so:

angular.module('myApp', [])
   .config(function($httpProvider) {
      $httpProvider.defaults.headers
        .mon['Accept-Language'] = 'bs-Latn-BA';
});

We can also manipulate these defaults at run time using the defaults property of the $http object. For instance, to add a property for dynamic headers, we can set the header property like so:

$http.defaults
   .mon['Accept-Language'] = "bs-Latn-BA";

AngularJS you can set mon headers by using $httpProvider. Angularjs

Example:

var app = angular.module("app", []);

    app.config(["$httpProvider", function($httpProvider) {
        // set Accept-Language header on all requests to
        $httpProvider.defaults.headers.mon["Accept-Language"] = "bs-Latn-BA";
    }]);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745095687a4610963.html

相关推荐

  • angularjs - Change Accept-Language Header with javascript - Stack Overflow

    My API uses the Accept-Language header to get it's current language which returns the json transla

    16小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信