1

I have a form in a Java Spring application with the following Event Handler of the Submit Button:

$('#submit').click(function (e) {
  e.preventDefault();
  if ($('#form').valid()) {
    $('#submit_container').hide();
    $('#loading_container').show();
    $("#form").submit();
  }else{
    ...
  }
});

As you can see I am hiding the Div containing the submit button once clicked. But unfortunately I am receiving double POST requests (in the exact same second) of the form every few days.

How is that possible? I don't think it's disabled Javascript because the requests are happening on the exact same time.

Michael
  • 538
  • 1
  • 7
  • 16
  • I gather it's on the the server side you're seeing these "double posts"? – Jaromanda X Jul 29 '18 at 00:50
  • if your submit button is an try changing it to a plain – Bobby Axe Jul 29 '18 at 00:53
  • @BobbyAxe Why do you think that might solve the problem? – CertainPerformance Jul 29 '18 at 01:21
  • Do you have the button defined as input element with `type="submit"`? If so can you remove that since you are doing the actual submission in the click handler anyway? PS I do see `e.preventDefault()` but humor me. – Akrion Jul 29 '18 at 01:29
  • What's your HTML for #submit and #form look like? :) – LJD Jul 29 '18 at 01:29
  • @CertainPerformance nothing seems out of order from the code just thinking that maybe js isn't exactly catching the default submit action i could be wrong? – Bobby Axe Jul 29 '18 at 01:32
  • Browsers usually keep the form visible and active even after submit until the server responds to POST/GET submission this might be the issue in your case try [disabling the form](https://stackoverflow.com/a/4473801/6160662) after submission so user won't be able to hit submit a second time. – Vinay Jul 29 '18 at 03:44

0 Answers0