Hola.
Lo que quiero hacer es que me muestre un mensaje que Ajax lo obtiene desde un PHP. El PHP funciona bien. Pero el Ajax, me muestra el primer mensaje bien, y cuando quiero mostrar el segundo me dice "Undefined"
Aqui le dejo el script
Código:
var error_message
function errorState(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var error_message=null;
error_message=xmlHttp.responsetext;
}
return error_message;
}
function ajaxError(code){
xmlHttp=GetXmlHttpObject();
xmlHttp.onreadystatechange=errorState;
xmlHttp.open("GET","errorMessage.php?q="+code,false);
xmlHttp.send(null);
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
Ese de arriba es el de los errores
Código:
var xmlHttpd
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="checkUser.php"
url=url+"?q="+str
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
users_count=xmlHttp.responseText;
if(users_count!=0){
document.login.username.disabled=true;
document.login.username.className="correct_formfield";
return false; } else {
error_mes=ajaxError('e100'); <<< Este si lo muestra
document.getElementById("error").className="error";
document.getElementById("error").innerHTML=error_message;
document.login.username.disabled=false;
document.login.username.className="wrong_formfield";
document.login.login_bt.disabled=true;
}
}
}
function showPassword(str,pass){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="checkPassword.php"
url=url+"?q="+str+"&p="+pass
xmlHttp.onreadystatechange=passwordStep2
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function passwordStep2()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
password=xmlHttp.responseText;
if(password==1){
document.login.password.disabled=true;
document.login.password.className="correct_formfield";
document.login.login_bt.disabled=false;
return false; } else {
error_mes=ajaxError('e101'); <<<< Este me muestra undefined
document.getElementById("error").className="error";
document.getElementById("error").innerHTML=error_mes;
document.login.password.disabled=false;
document.login.password.className="wrong_formfield";
document.login.login_bt.disabled=true;
}
}
}
Salu2