473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

onunload and XMLHttpRequest - going nuts

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.

Feb 1 '06 #1
7 2909
tg****@gmail.com wrote:
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.


My guess is that the SELECT statement from the second page is received
a few milliseconds after the UPDATE statement.

You could loop the SELECT until it gets 1 result, (also limit it to
like 20 tries or something so it doesn't go forever)

Feb 1 '06 #2
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.

Feb 1 '06 #3

tg****@gmail.com wrote:
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.

Feb 1 '06 #4
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.

Feb 1 '06 #5
tg****@gmail.com 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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Feb 1 '06 #6
Thank you you are a genious. onbeforeunload. Why isnt this function
talked about more. This works EXACTLY as I want it to.

Thank you!!!

Randy Webb wrote:
tg****@gmail.com 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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Feb 3 '06 #7
tg****@gmail.com 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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 3 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: kaeli | last post by:
Hey guys, This error occurs ONLY in Netscape 7.0. Not in 7.1. So, I think it's a bug. Buuuut... Has anyone had this problem or know of a fix? When attempting to have an onunload function...
4
by: TDonohue | last post by:
I am trying to kill a cookie using onUnload if a user leaves the site or closes the browser window so someone else can't get a person's session. Does anyone know if there's a way to check where...
3
by: Laurent | last post by:
I am trying to use the onunload event to know when the user closes a popup by receiving a request on the web server. I have a main page from where the user opens a popup. What I want is when the...
3
by: Andrew Poulos | last post by:
In a frameset I have this: window.onload = function() { frames.onunload = function() { alert('I'm going now'); } } when frames unloads I'm expecting the alert to be called but it never...
5
by: Matt Kruse | last post by:
I'd like to test for Opera8.00's missing setRequestHeader method before actually instantiating the object. For example, this works in firefox: if (XMLHttpRequest.prototype.getRequestHeader) { ......
1
by: Elizabeth Harmon | last post by:
Good Evening, I am new to the XMLHTTPRequest Object and it's use but i am doing pretty good with it since it's realtively simple? I am having one problem in using a Get method. I am...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
0
acoder
by: acoder | last post by:
Problem onload and onunload events do not fire when going back, forward or refreshing the page Browser Opera Example Any code using onload or onunload, e.g. window.onload = init; where...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.