I have some code like:
function duplicatecheck(value, colname) {
var invoiceLineId = $('tr[editable="1"]').attr('id');
var invoiceLine = {
InvoiceLineId: invoiceLineId,
InvoiceId: invoiceId,
ActivityId: value
};
$.post('/Invoice/InvoiceLineExistsForThisActivity/', invoiceLine, function (data) {
if(data == true) {
return[ false, "An invoice line already exists with this activity"]
}
else {
return[ true, ""];
}
});
}
The problem is that duplicatecheck
is supposed to return a value. The value is inside the post
callback function. So duplicatecheck
runs and doesn't return anything because post
is asynchronous and duplicatecheck
finishes before the callback has even run.
Is there a way to make duplicatecheck
wait until the callback has finished and return what the callback returns.
Am I going about this completely the wrong way and should be doing something else?