onunload and XMLHttpRequest - going nuts

T

tgh003

I have been at this for hours now. Pulling my hair out.

I have a standard php page that has an onunload event on it. The
onunload event sends a xmlhttprequest that triggers a database update,
for simplicity lets say it updates a table:
UPDATE testtable SET testfield = '".$_GET['rand']."' where id = 1

This works just fine.

Then the next page you navigate to is supposed to call the testfield
from the database and it should display the newly updated value. It is
not. If you refresh the next page again you now get the correct newly
inserted value.

Does the onunload event prefetch the next page prior to executing the
onunload function???

Anyone have any ideas?? I cant find anything in the archives about
this.

Thanks.
 
T

tgh003

i have an alert statement after the update on the initial page so that
is not the issue as i can see that the value is being updated
correctly. but the next page still has the old value.

it is very strange.
 
J

jshanman

i have an alert statement after the update on the initial page so that
is not the issue as i can see that the value is being updated
correctly. but the next page still has the old value.

it is very strange.

Is there only one link that goes to the next page, or can a differant
function be run when x is clicked, then have the function forward the
person to the next page after the XMLRequest Success code is returned?
If this works, then it has something to do with the onunload event.
 
T

tgh003

I figured out the issue. when onunload is executed the browser has
already called the new requested page (it has not rendered it yet - but
it has put it in its memory). therefore the value is still the old
one.

I guess we are back to the drawing board.
 
R

Randy Webb

(e-mail address removed) said the following on 2/1/2006 5:54 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
I figured out the issue.

Would the issue be you not quoting what you are replying to?

when onunload is executed the browser has
already called the new requested page (it has not rendered it yet - but
it has put it in its memory). therefore the value is still the old
one.

I guess we are back to the drawing board.


onbeforeunload can be your friend.
onclick can also.
 
T

tgh003

Thank you you are a genious. onbeforeunload. Why isnt this function
talked about more. This works EXACTLY as I want it to.

Thank you!!!
 
R

Randy Webb

(e-mail address removed) said the following on 2/3/2006 2:25 AM:
Thank you you are a genious. onbeforeunload. Why isnt this function
talked about more. This works EXACTLY as I want it to.

Please don't top-post either. It makes following a conversation difficult.

onbeforeunload isn't talked about a lot because of support, or lack of,
for it in different browsers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top