Added check for XMLHttpRequest to ensure redirection