I have wrapped a common ajax call into a function. It pings a script, returns JSON.
However for the life of me I can't seem to be able to have the JSON object be the return value of the function.
Must be something fairly simple I am missing, bu for the life of me can't work it out.
function queryCostCenter(user_id, currency_id, country_id){
var output = null;
var destinations = new Array();
var destination = { qty:1, country: country_id };
destinations.push(destination)
var data = {
destinations : $.toJSON(destinations),
user_id : user_id,
currency_id: currency_id
};
$.ajax({
data: data,
type: 'POST',
url: '/lib/ajax/ajax_prepaid_cost_calculator.php',
success: function(data) {
output = data;
alert(output);
}
});
alert(output);
return json;
}
The alert() inside the ajax() call displays the json object, however if try and alert outside the function, and/or return the response from inside the ajax() call its value is null?!
Any help/pointers would be appreciated.