Jump to content

Waiting for MySQL response from server


egalp

Recommended Posts

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&params';
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.