简体   繁体   中英

Record are multiple recorded on DB after jQuery validation

I have problem I'm validating text field (click submit button) and if value is true then i need to use jQuery dialog to get another permissions (enter another code). But if user closing down the dialog box and click submit button again then dialog box come up again (this is good) user entering code in to dialog form and submitting. Then i have two records (duplicated) on my database. If user closing-submitting dialog box 3 times then i have 3 dublicated records:

$('#f_button').click(function(){

// validation

{

// if true
$("#dialog").dialog("open");
$("#test_button").click(function() {

    $.ajax({                 // validating text field in dialog
        type: 'POST',
        url: file.php',

        data: $('#form_name).serialize(),
        success: function validate(data1) {
            if (data1 == 1) {

                $("#text_field").css('background-color', '#00FF00');
                $('#another_form')[0].submit();

} else {    
                $("#text_field").css('background-color', '#FF0000');

                            }
        }
    })
});

您可以在完成所有验证后设置ajax发布请求,不要将其放置在“提交”按钮上,而是将其放置在对话框确认按钮上,这样您发布的请求就不会消失,您可以轻松处理

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM