Add the {async:false} option to your $.get. This tells JavaScript to wait for the response before continuing with the rest of the script. By default, AJAX is asynchronous.
On Mar 24, 4:13 am, aeg1s <aeg1s1...@gmail.com> wrote: > I have the following code: > > $('#r_0_0').blur(function() { > > var x = $('#r_0_0').val(); > var y="#d_0"; > $(y).empty(); > $.get("apps/P5001/call/LineItems.lasso?LITM=" + x + "&Line=" + > 'r_0_0' + "&TEST=" + y,function(data2){ > $(y).empty(); > $(y).append(data2); > },"html"); > > $('#addnew').click(); > > }); > > The last line "#addnew" is adding a new line to a html table, and the > other code is updating a div with information from a database call. It > is all processing correctly, except the "addnew" is running before the > database query. > > How can I get the "addnew" to wait for the prior commands to finish?