I have a problem while i am getting data from api in a function, it is collecting data late and not waiting for function to complete execution and skipping it and moving forward for next line execution.
function getQ(mid){
$.ajax({
url : "http://localhost:8080/modules/"+ mid ,
type : "get" ,
dataType : "json" ,
success : function( response , status , http ) {
$.each( response , function( index , item ){
var s = item.q;
var v = JSON.stringify(item.qIDfromDB)
console.log(str +": " );
dbAnswers.push({ text: s, value: v});
});
console.log(dbAnswers);
},
error : function( http , status , error ) {
alert( 'Some Error Occured : ' + error );
}
});
}