in reply to Re: Forcing output to a browser when perl is busy
in thread Forcing output to a browser when perl is busy

Hmmm, the Javascript sounds interesting along with a redirect. Do you know of any examples of that type of script that I can steal, er, borrow.
  • Comment on Re^2: Forcing output to a browser when perl is busy

Replies are listed 'Best First'.
Re^3: Forcing output to a browser when perl is busy
by hbo (Monk) on Jul 17, 2004 at 20:45 UTC
    <script language="Javascript1.1"> function justOneClick() { myform.clickme.disabled=true; // don't click me twice return true; // so the submit will go ahaed } </script> ... <form method="POST" name="myform" onSubmit="return justOneClick()"> ... <input type="submit" name ="clickme"> </form>
      Ah ha, cool. That works. Of course, I had to mess with it and break it. I have two submit buttons, a Preview and a Post. As is, it disables the Post submit and I get an alert if the system is slower than the timeout. However, if I add a disable for the Preview button, my form variable gets eaten and it always posts. Since my script checks for Preview and otherwise posts the message, it works, but Preview is now broken. Here's what I did to the script:
      <script language="Javascript1.1"> function justOneClick() { message.Post.disabled=true; // don't click me twice message.Preview.disabled=true; // don't click me twice setTimeout('alert("Your form has been submitted. Please be patien +t, I\\'m working on it.")', 2000); return true; // so the submit will go ahaed } </script>

      I can live with only disabling post as it's the one that can take a while. Usually, the system is plenty fast for previewing. Apparently the name of the button gets eaten all together as my Post or your clickme doesn't exist in the form after the submit. Weird.

      Thanks.

Re^3: Forcing output to a browser when perl is busy
by ccn (Vicar) on Jul 17, 2004 at 20:45 UTC
    something like this
    <form onsubmit="if(this.submitted){ alert("please be patient"); return + false;}; this.submitted=true"> ... </fode>
Re^3: Forcing output to a browser when perl is busy
by hsinclai (Deacon) on Jul 17, 2004 at 22:18 UTC
    Here's a transfer chunk.. time is in millisecs

    <script> transfer_location = "http://new_url/"; pause_time = 600; function transfer() { if (document.images) setTimeout('location.replace("'+transfer_location+'");',pause_tim +e); else setTimeout('location.href = transfer_location;',pause_time); } </script>


Re^3: Forcing output to a browser when perl is busy
by bart (Canon) on Jul 18, 2004 at 15:38 UTC
    IMHO the Javascript approach is the least interesting route. What if:
    • The user disabled Javascript
    • The connection to the server really did fail. This is something people visiting Perlmonks should be familiar with... ;-) You're only going to annoy users, who'll lose posts this way.
    In my eye, using a unique (session) id per post, be it submitted or not, is the only way. The server can then choose to either reject posts with the same id, or use it to update an earlier submission (by the same user!)

    You can combine that with a quick response page, which might even automatically reload after a short while. See merlyn's WebTechniques column "Search in progress" page for some ideas.

      True, everything has a gotcha. Thus far, the Javascript has taken care of the problem. However, it's not perfect. I'm in the process of porting all this code for mod_perl and re-writing major sections. Doing the redirect would be simpler to add at that time. Assigning a unique id would be the best solution; however, the message and the reply dialogue are just html pages, so it's not possible as far as I know without a fairly major architectural change.