Preventing double HTTP POST

前端 未结 11 855
死守一世寂寞
死守一世寂寞 2020-12-29 05:23

I have made a little app for signing up for an event. User input their data and click \"sign me in\".

Now sometimes people are double in the database, the exact sam

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 05:58

    Almost no one has js disabled. Think about coding your e-commerce website for the 70 year old woman who double clicks every link and button. All you want to do is add a javascript to prevent her clicking "Order Now" twice. Yes - check this at the server side too "be defensive" - but don't code for that case. But for the sake of a better UI do it on the client side too.

    Here are some scripts that I found:

    //
    // prevent double-click on submit
    //
      jQuery('input[type=submit]').click(function(){
        if(jQuery.data(this, 'clicked')){
          return false;
        }
        else{
          jQuery.data(this, 'clicked', true);
          return true;
        }
      });
    

    and

    // Find ALL 
    tags on your page $('form').submit(function(){ // On submit disable its submit button $('input[type=submit]', this).attr('disabled', 'disabled'); });

提交回复
热议问题