Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
XMLHttpRequest gets url but can't redirect

I'm making a login form true an XMLHttpRequest. When a user enters incorrect details, a message will show up with an error. But when a user enters correct details, he should go to a new page (dashboard).

This is a part of my PHP

<?PHP 

// Details are correct
$output = header('Location:dashboard/index.php');

// Details are incorrect
$output = '<h6 class="omessagetext" id="error" style="color: #f05461">Incorrect e-mail or password</h6>';

?>

This is my javascript

var data = new FormData();
    data.append("email", document.getElementById("inputmail").value);
    data.append("password", document.getElementById("inputpassword").value);


var xhr = new XMLHttpRequest();
xhr.open("POST", "login.php");
xhr.onload = function() {
    
    if (xhr.readyState == 4 && xhr.status == 200) {
    
    var responsetext = xhr.responseText;
    
    if (responsetext.location){
        window.location.href = responsetext.location
    }else {
        document.getElementById('errordiv').innerHTML = responsetext;
    }
    
    }
};

xhr.send(data);

return false;

I've searched a lot but can't find the answer. Hope you can help me!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda