Windows位置不要在XMLHttpRequest之后重定向
Windows Location don't redirect after XMLHttpRequest
我有这些代码与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...";
}
}
问题是,当一个成功的注册发生(这些发生在xmlhttprequest的responseText没有字符串"cuenta"),不要重定向到我:"index.php?creada"。
我测试过了。效果很好。代码:
var oAjax = new XMLHttpRequest();
oAjax.open('GET', 'a', true);
oAjax.send();
oAjax.onload = function() {
if (oAjax.status == 200) {
window.location = 'http://baidu.com';
}
};
还有,检查你的错误信息!
相关文章:
- XMLHttpRequest未返回值-状态202
- XMLHttpRequest在移动设备上的chrome上不起作用
- AJAX简单错误.XMLHttpRequest无法加载http://localhost/mpl/getPage.php.
- 检查xmlhttprequest问题的消息
- 主线程上的同步XMLHttpRequest已弃用
- 如何定期发出xmlhttprequest
- javascript第三个XMLHttpRequest被拒绝.但前两个是允许的
- 上传带有XMLHttprequest的文件-多部分/表单数据中缺少边界
- 对象#<XMLHttpRequest>没有方法'完成'
- 在XMLHttpRequest之后重新初始化jQuery
- 如何将GreaseMonkey中的XMLHttpRequest延迟到目标页面加载完成
- Javascript XMLHttpRequest——只有第一个POST请求有效
- XMLHttpRequest - difference between Chrome & Firefox
- IE上的新XMLHttpRequest()出现JS Ajax未指定错误
- 非常简单的XMLHttpRequest不起作用
- 如何使用XMLHttpRequest下载文件
- XMLHttpRequest在$.ajax工作的地方给出了CORS错误
- XMLHttpRequest.open()AJAX中的参数url
- XMLHTTPRequest脚本中没有internet连接和超时
- 为什么当async标志设置为false时,xmlhttprequest中的代码可以工作,而当它设置为true时却不能工作