Php 如何在jquery中更正循环内的数据

Php 如何在jquery中更正循环内的数据,php,jquery,json,Php,Jquery,Json,我有下面的代码。当我点击回复链接时,它会显示一个评论框。 我要2分。 或者给我最好的工作方式 当1个注释框打开时,必须隐藏其他注释框 当我点击发送按钮时,正确的值应该发送vie序列化值 这些是代码 PHP代码 评论文本等。。。 Jquery代码 <script> $(function(){ $('.reply-comment').on('click', function(e){ e.preventDefault();

我有下面的代码。当我点击回复链接时,它会显示一个评论框。 我要2分。 或者给我最好的工作方式

  • 当1个注释框打开时,必须隐藏其他注释框
  • 当我点击发送按钮时,正确的值应该发送vie序列化值
  • 这些是代码 PHP代码

    
    评论文本等。。。
    

    Jquery代码

    <script> 
        $(function(){
            $('.reply-comment').on('click', function(e){ 
                e.preventDefault();
                $(this).next('.reply-comment-form').show();
            });
        });
    
    
        function send_comment()
        {   
            $.ajax({   
               type: "POST",
               data : $('.comment_form').serialize(),
               cache: false,  
               url: 'test.php',  
               success: function(data){
    
               }   
            });   
        }
    </script>
    
    
    $(函数(){
    $('.reply comment')。在('click',函数(e){
    e、 预防默认值();
    $(this).next('.reply comment form').show();
    });
    });
    函数send_comment()
    {   
    $.ajax({
    类型:“POST”,
    数据:$('.comment_form')。序列化(),
    cache:false,
    url:'test.php',
    成功:功能(数据){
    }   
    });   
    }
    
    php文件不需要。我正在通过firebug检查值。 请帮我澄清这个问题。 或者给我最好的工作方式

    我被困了两天。 谢谢您宝贵的时间。

    第一次

    $('.reply-comment').on('click', function(e){
    
        e.preventDefault();
    
        // Hide others
        $(".reply-comment-form").hide();
    
        // Show the one which is required
        $(this).next('.reply-comment-form').show();
    
     });
    
    第二,在表单上执行一个
    .on(“submit”…
    ),它将只序列化正确的输入字段

    更新:

    <form class="comment_form" method="post">     
          <textarea name="comment_box" rows="6" class="span10"></textarea> <br /><br />
          // Change type to submit and remove onclick
          <input type="submit" class="btn btn-primary" value="send" />
    </form> 
    
    $(".comment_form").on("submit", function(e){
        e.preventDefault(); // Here
        var _data = $(this).serialize();
        $.ajax({   
            type: "POST",
            data : _data,
            cache: false,  
            url: 'test.php',  
            success: function(data){
                console.log(data);
            }   
        });   
    
    });
    

    我找到了解决办法。@void帮了我这个忙

        $(".test").on("click", function(){
    
        var _data = $(this).parent().serialize();
        $.ajax({   
            type: "POST",
            data : _data,
            cache: false,  
            url: 'test.php',  
            success: function(data){
    
            }   
        }); 
    
    });
    

    谢谢!

    Hi,现在其他框隐藏了。但是表单是隐藏的。当我单击“提交”按钮时,所有表单值都会发送。那么你能告诉我如何使用onSubmit函数或禁用其他textares吗?当我在“提交”函数页面上使用时,将重新加载。我想通过ajax执行此操作,因为在这之后,值将作为json检索。你也可以这样做吗告诉我如何防止。我想要完全的ajax功能。谢谢你的时间。是的,你应该使用
    e.preventDefault()
    查看更新的回答。我在(“单击”)上使用,而不是在提交上。现在它可以工作了。但我想在单击提交按钮时发送值。而不是单击表单
        $(".test").on("click", function(){
    
        var _data = $(this).parent().serialize();
        $.ajax({   
            type: "POST",
            data : _data,
            cache: false,  
            url: 'test.php',  
            success: function(data){
    
            }   
        }); 
    
    });