Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-19-2005, 12:14 PM   PM User | #1
musa_ajk
New Coder

 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
musa_ajk is an unknown quantity at this point
Unhappy reload page and bypass alert message

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.

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

Last edited by musa_ajk; 08-19-2005 at 12:17 PM..
musa_ajk is offline   Reply With Quote
Old 08-19-2005, 12:36 PM   PM User | #2
martin_narg
Regular Coder

 
martin_narg's Avatar
 
Join Date: Jul 2002
Location: Chamonix, France
Posts: 600
Thanks: 1
Thanked 3 Times in 3 Posts
martin_narg is an unknown quantity at this point
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
__________________
"Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
-Tommy Cooper
martin_narg is offline   Reply With Quote
Old 08-19-2005, 12:56 PM   PM User | #3
musa_ajk
New Coder

 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
musa_ajk is an unknown quantity at this point
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.
musa_ajk is offline   Reply With Quote
Old 08-19-2005, 01:16 PM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 08-19-2005, 02:59 PM   PM User | #5
musa_ajk
New Coder

 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
musa_ajk is an unknown quantity at this point
Hello.

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

Any other ideas?

musa_ajk is offline   Reply With Quote
Old 08-19-2005, 03:45 PM   PM User | #6
musa_ajk
New Coder

 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
musa_ajk is an unknown quantity at this point
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.
musa_ajk is offline   Reply With Quote
Old 08-19-2005, 07:16 PM   PM User | #7
martin_narg
Regular Coder

 
martin_narg's Avatar
 
Join Date: Jul 2002
Location: Chamonix, France
Posts: 600
Thanks: 1
Thanked 3 Times in 3 Posts
martin_narg is an unknown quantity at this point
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/arti...amicselect.php
http://www.alistapart.com/articles/complexdynamiclists/

Hope this helps

m_n
__________________
"Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
-Tommy Cooper
martin_narg is offline   Reply With Quote
Old 08-22-2005, 01:26 PM   PM User | #8
musa_ajk
New Coder

 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
musa_ajk is an unknown quantity at this point
Quote:
Originally Posted by martin_narg
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/arti...amicselect.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?
musa_ajk is offline   Reply With Quote
Old 08-22-2005, 01:38 PM   PM User | #9
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
This script sends request to the server without reloading the page.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 08-22-2005, 01:46 PM   PM User | #10
musa_ajk
New Coder

 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
musa_ajk is an unknown quantity at this point
Thanks Glen. I'll have a look at the script to see how it works.
musa_ajk is offline   Reply With Quote
Old 08-22-2005, 03:11 PM   PM User | #11
musa_ajk
New Coder

 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
musa_ajk is an unknown quantity at this point
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.
musa_ajk is offline   Reply With Quote
Old 08-23-2005, 06:01 AM   PM User | #12
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app

Last edited by glenngv; 08-23-2005 at 06:05 AM..
glenngv is offline   Reply With Quote
Old 08-23-2005, 05:45 PM   PM User | #13
musa_ajk
New Coder

 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
musa_ajk is an unknown quantity at this point
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.
musa_ajk is offline   Reply With Quote
Old 08-24-2005, 02:53 AM   PM User | #14
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Quote:
Originally Posted by musa_ajk
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.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 08-24-2005, 10:05 AM   PM User | #15
musa_ajk
New Coder

 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
musa_ajk is an unknown quantity at this point
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?

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.
musa_ajk is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:11 PM.


Advertisement
Log in to turn off these ads.