I have created a special function which contains an jQuery ajax call. I feed the variable "settings" which is an array containing all the options needed to operate. The issue is that the function returns the data back to an array.
The ajaxPost function below works and collects the data and has been tested using alert(data); however when it gets to the test function the alert comes up undefined. It was my understanding that async:false should complete the function before continuing. Is there a way to fix the issue?
// jQuery Post function
function ajaxPost(settings){
showLoading(settings.loading);
$.ajax({
async: false,
url: settings.file,
type: "POST",
data: settings.vars
}).done(function(data){
hideLoading();
return data;
}).fail( function(xhr, textStatus, errorThrown) {
displayAlert('red',settings.bad);
console.log(xhr.responseText);
hideLoading();
return '0';
});
}
// Function Calling ajaxPost();
function test(){
var settings = {
'file':'../functions/admin/setup/setup.php',
'loading':'Creating Facilities',
'vars':$('#wiz').serialize()
}
var test = ajaxPost(settings);
alert(test);
}