var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onreadystatechange = function(){
if (this.readyState == 4) {
// пришел ответ
if (this.status == 301) {
// сервер просит нас перейти на новый адрес
var url = this.getResponseHeader('Location');
location.href = url;
}
}
}