egalp Posted January 13, 2007 Share Posted January 13, 2007 Is there a way for an AJAX operation to know if a MySQL query such as INSERT or UPDATE has finished?I assumed that by returning the result of such a query it should imply that it's finished, but in reality it appears not to be the case.->I am using the Prototype framework to insert some rows into MySQL via PHP, and then the onComplete event refreshes a window with (hopefully) the inserted rows. However, sometimes the refresh returns only rows that existed before the insertion, meening somehow the second request is issued before the table has finished updating. Right now I'm avoiding the issue by using window.setTimeout for 100 ms, but I'm looking for a way for the AJAX request to know when the table is updated with the insertion of the new rows. Is there a way to accomplish this?At first I tried this:[code]<script type="text/javascript">var params = 'insertion¶ms';var element = 'some_element_id';var myAjax = new Ajax.Request( '/insertionAction/path/', { method: 'post', parameters: 'submit&'+params, onComplete: refresh(element,'/retrieveAction/path/') }function refresh(el,action){ element = $(el); var myAjax = new Ajax.Request( action, { method: 'post', parameters: 'submit&refresh', onComplete: function (t) { element.innerHTML = t.responseText; } });}</script>[/code]However this would refresh the element with the old rows (before the insertion).I changed it the following way so it would work for now:[code]onComplete: window.setTimeout('refresh(element,'/retrieveAction/path/')', 100)[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.