The answer @Pekka pointed to is probably your best bet. It's actually an elegant solution, considering there is no such facility in JavaScript itself.
The author of the solution provides a very clear example:
var language;
$.ajax({
url: "http://ajaxhttpheaders.appspot.com",
dataType: 'jsonp',
success: function(headers) {
language = headers['Accept-Language'];
nowDoSomethingWithIt(language);
}
});
Of course, you could set language
to some default value. And the result is an unparsed string, so there would need to be some more logic in nowDoSomethingWithIt()
.
Have a look at this working demo: http://jsfiddle.net/seYLA/