简体   繁体   中英

Windows Location don't redirect after XMLHttpRequest

I have these code with a XMLHttpRequest:

function Registrarse()
{
    conexionRegistrarse = new XMLHttpRequest();
    conexionRegistrarse.onreadystatechange = procesarRegistro;
    conexionRegistrarse.open('GET', 'index.php?registrarse=&username='+username+'&mail='+mail+'&pw='+contraseña+'&pwr='+repetircontraseña, true);
    conexionRegistrarse.send();
}

function procesarRegistro()
{
    var detalles = document.getElementById("labelUsername");

    if(conexionRegistrarse.readyState == 4)
    {
        if((conexionRegistrarse.responseText).indexOf("cuenta") == -1)
        {
            window.location = "http://localhost/index.php?creada";
        }
        else
        {
            detalles.innerHTML = conexionRegistrarse.responseText;
        }
    }
    else
    {
        detalles.innerHTML = "Cargando...";
    }
}

The problem is that when a succesfull register happen (these occurs when the responseText of the xmlhttprequest don't have the string "cuenta"), don't redirect me to: "index.php?creada". I try with assign() and neither work.

I tested. It works very well. code As:

 var oAjax = new XMLHttpRequest(); oAjax.open('GET', 'a', true); oAjax.send(); oAjax.onload = function() { if (oAjax.status == 200) { window.location = 'http://baidu.com'; } }; 

as well, check your error message!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM