Repeated submission of forms

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.