0

Im new to ajax.. please bear with me.. My code is as follows:

function checkempid(){

    var status;
    xmlHttp=GetXmlHttpObject();
    var urlemp="postemployee";
    urlemp=urlemp+"?employeeId="+document.PostAvailableBench.employeeId.value;
    xmlHttp.onreadystatechange=stateChangedemp ;
    xmlHttp.open("GET",urlemp,true);
    xmlHttp.send(null);
    var showdata;

    function stateChangedemp(){ 
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    showdata = xmlHttp.responseText;
    alert(showdata);

     if(showdata.trim()=="available"){
        alert("inside if");
       saveReportFinished(true);
    }
    else{
        alert("inside else");
        saveReportFinished(false); 
        }
    }
    }

    function saveReportFinished(success) {
        if (success == true)
        {
        status = true;
        }
        else
        {
        status = false;
        }
    }

    function GetXmlHttpObject(){
    var xmlHttp=null;
    try{
      xmlHttp=new XMLHttpRequest();
     }
    catch (e) {
     try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e){
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
}

    return status;

}

Im trying to set the 'status' which is a global variable inside 'saveReportFinished' function and trying to return the status by using 'return status'.. but it returns only the initial value and does not return the values in saveReportFinished function. I will be glad if someone could help me.. Thank You in advance!

1 Answer 1

1

I think a better way of doing it would be to return the status from saveReportFinished and avoid using a global. I'm also a little confused why you using the saveReportFinished method if you returning the same value that you passing in...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.