Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser on submit with jquery

Tags:

html

jquery

On submit of a form I show a blocking message "Please wait" with following code:

$(document).ready(function() { 
  $('form').submit(function() {
    $.blockUI({ message: "<h1 id='waitingmessage'>Plz wait ...</h1>" });
  });
}); 

That works ok for me.

If the user presses F5 now, the browser ask for resubmit. The user is allowed to. But the script above does not trigger anymore.

How can I trigger this resubmit with jquery, thus the waitingmessage is still shown?

Thx

Chris

EDIT: The submit of the form goes to the same adress as the form. I only distinct on the controller side between GET and POST. If it was a POST, I process the received data, otherwise I show only the blank form. The user is allowed to send data twice or as often as wanted. So after the first POST the user can press F5 to resubmit the data, and he is totally allowed to. It's just that the waitingmessage does not appear any more. So I need maybe a more general solution "onpost". Does something like that exist?

SOLUTION:

$(document).ready(function() { 
   $('form').submit(function() {
      $.blockUI({ message: "<h1 id='waitingmessage'>Bitte warten ...</h1>" });
   });

   $(window).keydown(function(event){
      if (event.keyCode == '116' && '${request.method}' == 'POST') {
         $.blockUI({ message: "<h1 id='waitingmessage'>Bitte warten ...</h1>" });
      }
   });
});

And request.method is set server side and is either 'GET' or 'POST' thus I know where the user came from.

like image 927
Christian Avatar asked Mar 24 '26 20:03

Christian


1 Answers

It seems that I don't have perfect solution too. I will do only for only first F5 event

<script type="text/javascript">
$(function ()
{
    $(window).keydown(function (e)
    {

        if(e.keyCode == 116){
            submitform();
            return false;
        }
        alert(e.keyCode);
    });
})

function submitform()
{
    alert("hello");
}
</script>

<form id="myform" action='test.php'>
    <input id="submit" type="submit" onclick="submitform(); return false;"/>
</form>
like image 159
Santosh Linkha Avatar answered Mar 27 '26 10:03

Santosh Linkha