Help to understand, please. Cannot use result of ajax request.

$.ajax({ async: true, type: "POST", url: "/ajax_que.php", dataType: "json", success: function(data_db) { var answer = data_db; console.log(data_db); for(var i = 0; i < answer.length; i++){ console.log(answer[i]); } }, complete: function draw(){} }); 

Actually, if I use a loop inside ajax

 for(var i = 0; i < answer.length; i++){ console.log(answer[i]); } 

That's all ok.

But I need to work with answer (this is an associative array) inside the draw function.

    1 answer 1

    1. Do you really need it? You have the same success , and the data is already there.
    2. In complete , you can also pull out the data.

    Something like this:

      complete: function draw(res){ var answer = res; } 
    • Yes really. In draw, this associative array should be used) - Natali