samedi 5 novembre 2016

JavaScript if data is undefined self invoke the function

I'm learning JavaScript. And now I have first problem and I can't find solution. I tried solutions from this site, but it didn't help.

My problem is: I'm calling JSON response via jQuery, and if I get "undefined" I just simply want to invoke the function which gets JSON data again and again and stop when the returned data is correct.

I think $.getJSON code isn't necessary. Most important problem (I think) is here:

var _regenerateRightDiv = function(content){
    var existingRightDiv = document.getElementById("rightDiv");

    if (typeof output !== "undefined")
     {
        existingRightDiv.innerHTML = content;
     }
    else {
        getData();
        setTimeout(function(){_regenerateRightDiv(content)}, 1000);
    }

}

I'm still getting (sometimes) content which is "undefined".

Thank you for help.

Aucun commentaire:

Enregistrer un commentaire