Ready State
Pessoal estou resgatando o html de uma URL usando XMLHttpRequest(), no entanto o código só funciona se eu colocar um alert() após o XMLHttpRequest().open(). Se eu não colocar alert() ele fica com o ReadyState = 0.
Segue o código para exemplificar:
// Carregar HTML
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(ex)
{
try {
ajax = new XMLHttpRequest();
}
catch(exc)
{
alert("Esse browser não tem recursos para uso do Ajax");
ajax = null;
}
}
}
if(ajax) {
ajax.open("GET", "[https://www.xxx.com",](https://www.xxx.com) true);
ajax.setRequestHeader("Content-Type", "charset=ISO-8859-1");
ajax.send(null);
alert("Enviando...."); // se eu tirar não funciona...
}
// Carrega HTML da popup na varriavel obj
function mudancaEstado(){
if(ajax.readyState == 4){
var obj = ajax.responseText;
}
}
ajax.onreadystatechange = mudancaEstado();
Alguém sabe o que eu posso usar para não ter que usar o alert()?
Discussão (2)
Carregando comentários...