I'm new to callbacks and trying to get this working. I don't want my getCustomerIdDescription returning anything to my popover until my post has returned data, but I get an error on the 'callback(supplierId)' line at the bottom that says 'callback is not a function' How do I write my callback so that nothing gets returned from getCustomerIdDescription until I have my post data?
Here is my code
scope.showCustomerIdList = function(value) {
$('#{0}'.format(value)).popover({
html: true,
container: 'body',
content: function() {
return scope.getCustomerIdDescription(value);
},
title: function() {
return 'Customer ID - Description';
}
}).popover('show');
};
scope.getCustomerIdDescription = function(supplierId, callback) {
var model = {};
model.clientId = scope.contextClientId;
model.supplierId = supplierId;
$.post(scope.enumControllers.GetCustomerIdsForSupplier, model, function(response) {
if (response.error == false) {
var ids = JSON.parse(response.ids);
var list = '';
_.each(ids, function(result) {
list += '<li>' + result.CustomerId + ' - ' + result.CustomerDescription + '</li>';
});
return '<ul>' + list + '</ul>';
} else {
return "Cound't Fetch Customer Ids";
}
}).fail(function() {
return "Cound't Fetch Customer Ids";
});
callback(supplierId);
};