0

I'm a newbie in javascript and write a little app, but I know that onload an asynchronously function is and return not work. Have anyone an idea?

See this

Thanks for your help

function onDeviceReady() {
    if (function1()){
        if (getDBsettings()){
            if (function3()){
                dostuff;
            }
            else{
                alert("");
            }
        }
        else{
           alert(""); 
        }                     
    }
    else{                    
       alert(""); 
    }
}

    function getDBsettings(){
    var xmlhttp= new XMLHttpRequest();
    xmlhttp.open("POST","http://abcdefgh.php", false);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.onload = function(){
        if(xmlhttp.status == 200){
            var json_string = xmlhttp.responseText;
            var json = JSON.parse(json_string);
            if(json.success===1){
                return true;
            }
            else{
                return false;
            }
        }
        else if(xmlhttp.status == 404){
            return false;
        }
        else{
            return false;
        }
    };
    xmlhttp.send();
}
Mathmos
  • 1
  • 3
  • [documentation](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Monitoring_progress) on MDN has a yellow note saying "You need to add the event listeners before calling open() on the request. Otherwise the progress events will not fire." Related? – traktor Feb 19 '16 at 01:44
  • Also the onload function is a callback for an asynchronous request and does not affect the value returned by function `getDBsettings` which, in fact, returns `undefined`. – traktor Feb 19 '16 at 01:57

0 Answers0