I try to retrieve the “accept-language” HTTP header value with jQuery in this way:
$(document).ready(function () {
//Ask ASP.NET what culture we prefer, because we stuck it in a meta tag
var data = $("meta[name='accept-language']").attr("content")
});
The HTTP header is present because I can see it with the Chrome Network console tab "Accept-Language:en-US,en;q=0.8,de;q=0.6,es;q=0.4", but I always get undefined value.
Any idea?
You need to notice, that this code is not retrieving the actual header, but value which has been put into
METAtag (JavaScript doesn’t have access to the headers of original request). In the article you have linked you have this helper:Which you need to add to your project, and then use in view like this: