非常特殊-第一次提交一次,第二次提交两次,第三次提交三次,依此类推..等等...我做错了什么? [英] Very peculiar - submit once the first time, twice the 2nd time, trice the 3rd time .. and so on .. what I did wrong?

查看:98
本文介绍了非常特殊-第一次提交一次,第二次提交两次,第三次提交三次,依此类推..等等...我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用可通过ajax帖子提交已编辑信息的模式表单.事情是,它第一次提交一次..再次启动模态表单,然后提交,然后两次提交,依此类推.有人曾经有过这样的经历吗?请帮忙.

Working with a modal form that submits edited information via ajax post. The thing is, it submitted once the first time .. fire up the modal form again, then submit, and twice it goes and so on and so forth. Does anyone had this sort of experience before? Please help.

$("#editInfo").click(function () {
    valform = ["realname","email"];
    valneed = 2;
    $('#smallModal .modal-body').empty();
    $('#smallModal .modal-body').load('/profile.php?action=profile_edit_info');
    $('#smallModal .modal-title').text('Edit Personal Information');
    $('#smallModal').modal('show')

    $('#smallModal').on('shown.bs.modal', function () {
        $("#smallModal #profileeditinfoform").keydown(function(event){
        if(event.keyCode == 13 && event.target.nodeName!='TEXTAREA')
            {
                event.preventDefault();
                return false;
            }
        });

        $("#realname_comment").hide();
        $("#email_comment").hide();

        $('#realname').bind("change", function() {
            $('#realname').addClass("spinner");
            var v_realname = verifyVar($('#realname').val(),'name');
            displayVerify(v_realname,'realname');
        });

        $('#email').bind("change", function() {
            $('#email').addClass("spinner");
            var v_email = verifyVar($('#email').val(),'email');
            displayVerify(v_email,'email');
        });

        $("#editinfo_submit_btn").click(function(event) {
            event.preventDefault();
            $('#loader').fadeIn();

            formData = $("#profileeditinfoform").serialize();
            var v_submit = submitEditInfo(formData);
            verifySubmitEditInfo(v_submit);

            $('#loader').fadeOut();
        });
    });
});

function submitEditInfo(data) {
    var alldata = data + '&action=profileeditinfo';
    return $.ajax({
        type: 'POST',
        cache: false,
        data: alldata,
        url: '/ajax/submit.php'
    });
}

function verifySubmitEditInfo(ajaxCall) {
        ajaxCall.success(function(realData) {
                response = JSON.parse(realData)
                if (!response.success) {
                    $.gritter.add({
                        title: response.title,
                        image: '/img/custom/fail.png',
                        sticky: false,
                        text: response.message
                    });
                } else {
                    valform = [];
                    $("#submitdiv").hide();
                    $("#profileeditinfoform").find("input:text").val('');
                    $('#infodiv').slideUp(200).load('/divloader.php?req=profile_info').slideDown(200);
                    $.gritter.add({
                        title: response.title,
                        image: '/img/custom/success.png',
                        sticky: false,
                        text: response.message
                    });
                    $("#smallModal").modal('hide');
                }
        });
}

推荐答案

每次单击时,都会添加一个新的事件处理程序:

Every time you click, you're adding a new event handler:

$('#smallModal').on('shown.bs.modal' //...

您确定要在点击"上执行此操作,还是最好在点击处理程序之外进行设置?

Are you sure you want to do this on "click", or might it be better to set this up outside of the click handler?

实际上,您将事件处理程序绑定为对整个此代码中其他事件的响应.除非您在完成操作后将它们解除绑定,否则这可能不是一个好主意.

In fact, you're binding event handlers as a response to other events all over this code. That's probably not a great idea, unless you unbind them once you're done.

这篇关于非常特殊-第一次提交一次,第二次提交两次,第三次提交三次,依此类推..等等...我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆