Clearing an event

1

I'm creating a comment system with a response only when it's time to respond twice to the bank when I send a comment, I did the slide response system where you open one and close the other, only when the next one opens to comment and close the previous one is still loaded and counts as if it were two answers does anyone know how to solve?

code

    function addEventosRespostas() {
        $(document).on("click", ".resposta", function(){
            var id = $(this).children('input').val();

            $('.coment').find('.resp').fadeOut("slow");
            $(this).parents('.coment').find('.resp').fadeIn("slow");

            $(document).on("submit","form", function() {

                var texto = $(this).children('textarea').val();
                var coment_id = $(this).find('#id_coment').val();
                var id_user_coment = $(this).find('#id_user_coment').val();

                    $.post('swith/viwer.php',{
                        acao: 'resposta', texto: texto, coment_id: coment_id, id_user_coment: id_user_coment},
                            function(){
                                $('.dialog').fadeIn();
                                $('form textarea').val("");
                                $('form input[type = submit]').val("responder");
                                $('.closemodal').click(function(){
                                        $('.dialog').fadeOut();
                                });
                            });
            return false;
            });

        });
    }

// Exibir mais comentários



    $('#load').on("click",function(){

        loadmo = $(this);
        var video = $('#link').val();
        var numcom = $('.comentar .com').length;

        $.post('swith/viwer.php',{
            acao:'comentarios', video: video, numcom: numcom},function(contcom){

            if(contcom => 1){
                $.post('swith/viwer.php',{
                    acao:'morecoment', video: video, numcom: numcom},function(morecom){

                    $('.comentar .com:last').after(morecom);
                    $('.comentar .com').fadeIn("slow");
                    addEventosRespostas();





                }); 

            }

            if(contcom > 1){

            }else{
               loadmo.fadeOut("fast"); 
            }
        });
    });

// Responder Comentário        



        addEventosRespostas();

php code

<div class='comentar  fl-left'>
                        <div class='coment com' >

                                <?php 

                    if($foto == "" || $foto == "uploads/"):
                        echo  "<a href='user?id={$id}'><img class='fl-left' src='".REQUIRE_PATH."/css/boot/icons/thumb.png'></a>";
                    else:
                        echo  "<a href='user?id={$id}'><img class='fl-left' src='{$imx['foto']}'></a>";
                    endif;
                    ?>
                   <p><small class='fontze1'>Comentado por:</small> <?=$nome?> <small>Em:  </small> <?=$date?> <small>As: </small> <?=$hora?></p>

                   <div class="comentando">
                       <p><?=nl2br($comentario)?></p></div>
                       <div class='fl-right resposta'>Responder<input type='hidden' value='<?=$big[id] ?>' name='idcoment'>
                       </div>
                       <div class=' resp' style='display:none'>
                           <form method='post' id="comentarios" class="formulario" >
                               <input type="hidden" value="<?= $big['id'] ?>" id="id_coment" >
                               <input type="hidden" value="<?= $_SESSION['mail'] ?>" id="id_user_coment" >
                               <textarea id="texto"></textarea>  

                               <input class='btn btn-green' type='submit' value='responder' name='responder'>
                           </form>
                       </div>
                   </div>
    
asked by anonymous 03.06.2017 / 06:17

1 answer

0

This is happening because you add the event:

 $(document).on("submit","form",function());

twice, so if a form to submit it will fall into both understand? I made an example where you will clearly see this happening.

Example

One solution would be to just add the code one time example:

 $(document).on("submit","form",function());

This will get all the submits of "form". I hope I have helped, if you have any doubt or need to explain it to you, you can comment below.

    
03.06.2017 / 07:24