It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

xmlhttp.readyState==4 doesn't fire unless I put alert("")

xmlhttp.readyState==4 doesn't fire unless I put alert("")

Postby venkat_walking on Sat Jul 10, 2010 6:22 pm

Hello all,

I am creating an web application where I am now checking whether a emailId is already registered with us or not".If the emailid exists the appropriate message is reflected in div_Error.innerHtml

But there is something unusual happening here. If I dont put alert() statement in the first line of fun_getOutput() function then xmlhttp.readyState == 4 doesn't fire. And same If I put it then it works like a charm.

Is it some time delaying problem in Javascript/Ajax.
Please discuss.
Code: Select all
function fun_GetXmlHttpObject()
{
    if (window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
   
    return null;
}

function fun_AjaxCheckExistingEmailId(EmailId)
{

    xmlhttp=fun_GetXmlHttpObject();

    if (xmlhttp==null)
    {
        return;
    }

    url="ajax_CheckExistingEmailId.jsp?";
    url+="textfield_EmailId="+EmailId;
    xmlhttp.open("POST",url,true);
    xmlhttp.send(null);

    xmlhttp.onreadystatechange=fun_getOutput();

}

function fun_getOutput()
{
     alert("**** [b]I DONT KNOW WHY THIS IS REQUIRED[/b] ****");

    [color=#FF4000] //But if I comment the above alert statement it doesn't go inside below [B]IF[/B] block,  Othewrwise it works like a charm. [/color]
    if (xmlhttp.readyState==4)
    {
          var div_Error =document.getElementById("div_Error_Id");
          if(xmlhttp.responseText.indexOf("EmailId_Exists")!=-1)
          {
               div_Error.innerHtml="Email Id Exists"
           }
          else{
                   div_Error.innerHtml="Ok"
           }
     }
}
     



Thanks,

Venkat
venkat_walking
 
Posts: 5
Joined: Mon May 11, 2009 4:56 pm

Who is online

Users browsing this forum: No registered users and 5 guests