I am struggling with an issue to solve my problem for hours already! I want to do store the success values of my ajax request in a global var in my JS code. While AJAX is asynchron, it doesn't work to the time I would like it to work, I know that already. The problem is: How can I still solve the problem, that I get the data in a array/var from the success? I read and tried a lot, but nothing worked.
That's my code snip:
var result = "";
function InitIndexIDs(){
    $.ajax({
        type: "POST",
        url: "ajax/appendTable.php",
        dataType: "json",
        success: function(data) {
              result = data 
              console.log(result) // success
        },
    });
}
console.log(result) // ---> "" 
I have read about setting it to asynchron, which would work, but is supposed to be a bad idea, because it would trigger more problems, than solve it.
So what can I do, to solve my Problem? Thank you very much!
