To solve the problem of repeated form submission, a registry ticket uses ajax to submit a form. how can this problem be prevented from repeated forms, this means that after the user submits a request, the user submits the form again before returning the result for some other reasons, causing repeated data. could you please advise on any good solutions?
Reply to discussion (solution)
Take a look at the following code:
namespace{flags:{}}namespace.flags.submit=true;document.getElementById('btn').addEventListener('click',formSub);function formSub(){ if(namespace.flags.submit){ namespace.flags.submit = false; $.post('addr',{params:'},function(data){ if(data == 'OK'){ alert(OK'); namespace.flags.submit = true; } }); }}
Take a look at the following code:
namespace{flags:{}}namespace.flags.submit=true;document.getElementById('btn').addEventListener('click',formSub);function formSub(){ if(namespace.flags.submit){ namespace.flags.submit = false; $.post('addr',{params:'},function(data){ if(data == 'OK'){ alert(OK'); namespace.flags.submit = true; } }); }}
The main idea is to set a flag variable, which controls whether the variable can be submitted. The program is not fully written and can be improved by yourself.
Show a rotating chrysanthemum
Then set a sending switch