...

View Full Version : reload page and bypass alert message



musa_ajk
08-19-2005, 12:14 PM
Hi all.

Having problems with a bit of Javascript embedded in PHP code. The script is trying to reload (which works fine) but basically I want to reload a page and bypass (or confirm) the message alert which accompanies it (i.e. "the page cannot be refreshed without resending the information..."). The page being reloaded is a form and the fields refresh only upon a reload.

I've seen some posts re: this problem from 2003 on this site, but they don't seem to work. Any ideas anyone?

Thanks in advance. :confused:

code:
echo "<script language='javascript'>\n";
echo "{ history.go(-1); }\n";
echo "{ window.location.reload(); }\n";
echo "</script>\n";

martin_narg
08-19-2005, 12:36 PM
It's not possible to remove this message using javascript, BUT! it is possible to use a system whereby you do not encounter this message at all.

Querystrings - passing data through querystrings either by static links (mypage.php?id=99) or by using form GET method rather than POST.

Or if you do want to post the form, post it from page A to page B, page B processes the form then automatically redirects back to page A. If the user refreshes the page they can see (page A) as no form was posted there it will not bring up the warning message.

Hope this helps.

m_n

musa_ajk
08-19-2005, 12:56 PM
Thanks for replying.

Let me give you a bit more info.

- the form is a POST but this problem occurs before the form is submitted.
- within the form there are links which sends a string to a server.
- the server replies with info which goes into drop down lists within the form.
- the page needs to be reloaded to see the updated info in the drop down lists.
- the user selects info from lists and then SUBMITS.

Maybe this is a PHP problem but my first instinct was Javascript. Any other ideas?

Thanks. :confused:

Kor
08-19-2005, 01:16 PM
sounds like you want to post and get methods same time....

Anyway... try this:

echo "{ window.location.reload(true); }\n";
to force reloading straight from server... Not tested... but, who knows

musa_ajk
08-19-2005, 02:59 PM
Hello.

Tried that earlier on, and again, but same result.

Any other ideas?

:(

musa_ajk
08-19-2005, 03:45 PM
Hello.

I take it there's no way of acknowledging the prompt that appears - i.e. the script "pressing" the button on the highlighted retry button? :(

Thanks.

martin_narg
08-19-2005, 07:16 PM
So you're dynamically building select boxes based on previous user choices? I see what you're trying to do.

There's lots of resources to do this:
http://www.bobbyvandersluis.com/articles/unobtrusivedynamicselect.php
http://www.alistapart.com/articles/complexdynamiclists/

Hope this helps

m_n

musa_ajk
08-22-2005, 01:26 PM
So you're dynamically building select boxes based on previous user choices? I see what you're trying to do.

There's lots of resources to do this:
http://www.bobbyvandersluis.com/articles/unobtrusivedynamicselect.php
http://www.alistapart.com/articles/complexdynamiclists/

Hope this helps

m_n

Hey Martin, thanks for pointers - really helpful for future projects. However, my solution works except the page needs reloading inorder to show results obtained from server. Would the above solutions solve the reloading problem? I can see the potential of the above solutions, but the dynamic lists must be populated by the server - I cannot hardcode these. Is what I'm asking unfeasible? :cool: :D

glenngv
08-22-2005, 01:38 PM
This script (http://www.ashleyit.com/rs/jsrs/select/php/select.php) sends request to the server without reloading the page.

musa_ajk
08-22-2005, 01:46 PM
Thanks Glen. I'll have a look at the script to see how it works.

musa_ajk
08-22-2005, 03:11 PM
Intersting. Had a look at JSRS site and checked through the forums. Tried a suggestion of using location.replace - this gets the list requested and reloads without the retry fiasco, but the 'form data' from before the reload is lost.

Am I missing something very obvious here?

Here's the code in question:

(form data lost)
echo "<script language='javascript'>\n";
echo "{ history.go(-1); }\n";
echo "{ location.replace('prodoutlite.php'); }\n";
echo "</script>\n";

(reload provokes retry prompt)
echo "<script language='javascript'>\n";
echo "{ history.go(-1); }\n";
echo "{ window.location.reload(); }\n";
echo "</script>\n";

(page to get data from server loops)
echo "<script language='javascript'>\n";
echo "{ history.go(-1); }\n";
echo "{ location.replace('prodoutlite.php'); }\n";
echo "{ window.location.reload(); }\n";
echo "</script>\n";

Thanks in advance. :)

glenngv
08-23-2005, 06:01 AM
You will never get rid of that prompt if you won't change your implementation. That's the inherent behavior of POSTed data. location.replace is essentially the same with location.href. It just replaces the current page in the history with the specified url and it does not include the POSTed data (which you need) from the previous page.

Why not just implement what the JSRS site exactly does? It doesn't require reloading the current page. When the response from the server is received by the hidden iframe, the hidden iframe calls the javascript callback function in the main page to populate the comboboxes. It passes the data retrieved from the server to the callback function to dynamically create the option items.

musa_ajk
08-23-2005, 05:45 PM
Hey thanks for the pointers. Found a way to achieve what I wanted all along by changing the form from POST to GET - that simple. Learning more and more about PHP and Javascript, and I'm getting more enthralled by it all.

Cheers. :thumbsup:

glenngv
08-24-2005, 02:53 AM
Found a way to achieve what I wanted all along by changing the form from POST to GET - that simple.
That was the initial suggestion of martin_narg right there in post #2. But I thought you really want it to be POST not GET.

musa_ajk
08-24-2005, 10:05 AM
Oops! Hands up - I confess I missed that. I assume POST and GET are the same except the latter puts the variables on the end of the URL - or is there more to it than that? :o

Only problem I'm seeing now, while testing this, is the quirkyness of it running on MACs - no retry message comes up but neither does it reload, although a browser refresh shows the form fields have reloaded.

Thanks. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum