I'm using Chrome for my development, but I don't think there's anything browser-specific in my question.
I'm writing a Javascript app that needs to know the language the browser is using. According to this, I shouldn't use navigator.language
; I should instead perform some dummy ajax request and see what the browser put in the request's Accept-Language
header.
As far as I can tell, there's no way to access an ajax request's request headers programmatically. The xhr object I get back in my request's success callback has a method called getAllResponseHeaders()
, but mentions nothing about request headers.
If this is the correct methodology for getting the user's language preference, I must be missing something obvious. How do I access the Accept-Language
header from within Javascript? Or, if what I'm doing is as roundabout as it seems to me, what's an easier way to find out the user's language preference?