I am new to Ajax and I am attempting to use Ajax while using a for loop. After the Ajax call I am running a function that uses the variables created in the Ajax call. The fu
You should set async = false in head. Use post/get instead of ajax.
jQuery.ajaxSetup({ async: false });
$.post({ url: 'api.php', data: 'id1=' + q + '', dataType: 'json', success: function (data) { id = data[0]; vname = data[1]; } });