jQuery post inside another javascript function
<p>I have some code like:</p>

<pre><code>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, ""];
                    }
                });
            }
</code></pre>

<p>The problem is that <code>duplicatecheck</code> is supposed to return a value. The value is inside the <code>post</code> callback function. So <code>duplicatecheck</code> runs and doesn't return anything because <code>post</code> is asynchronous and <code>duplicatecheck</code> finishes before the callback has even run.</p>

<p>Is there a way to make <code>duplicatecheck</code> wait until the callback has finished and return what the callback returns.</p>

<p>Am I going about this completely the wrong way and should be doing something else?</p>
