Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    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

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello.

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

    Any other ideas?


  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    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

  • #8
    New Coder
    Join Date
    Aug 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    This script sends request to the server without reloading the page.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #10
    New Coder
    Join Date
    Aug 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Glen. I'll have a look at the script to see how it works.

  • #11
    New Coder
    Join Date
    Aug 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Last edited by glenngv; 08-23-2005 at 06:05 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #13
    New Coder
    Join Date
    Aug 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #14
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #15
    New Coder
    Join Date
    Aug 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •