最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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";
    }]);
发布评论

评论列表(0)

  1. 暂无评论