2017-03-10 03:58
浏览 87


I am using php while loop and want to get value for ajax. my code is

<form class="commentform">
  <input type="hidden" class="proid" name="proid[]" value="<?=$rr['id']?>">  
  <input type="text" class="form-control wac" name="comval[]" placeholder="Write a comment..">
<script type="text/javascript">
    $('.commentform').on('submit', function(e){
        var comment = $(this).next('.proid').attr('value');
        return false;

please guide to get value in while loop for ajax on form submit. Thanks in advance

图片转代码服务由CSDN问答提供 功能建议

我正在使用php while循环并希望获得ajax的值。 我的代码是

&lt; form class =“commentform”&gt; 
&lt; input type =“hidden”class =“proid”name =“proid [  ]“value =”&lt;?= $ rr ['id']?&gt;“&gt;  
&lt; input type =“text”class =“form-control wac”name =“comval []”placeholder =“Write an comment ..”&gt; 
&lt; / form&gt;  
 &lt; script type =“text / javascript”&gt; 
 $(document).ready(function(  ){
 var comment = $(this).next('。proid')。attr('value'); 
&lt; script&gt; 

请指导 在表单提交时获取ajax的while循环值。提前感谢

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongwuwu6104 2017-03-10 03:59

    You need to use .find()/.children() as input is a child not a sibling. Additionally use .val() to get the current value

    var comment = $(this).find('.proid').val();

    instead of

    var comment = $(this).next('.proid').attr('value');
    打赏 评论
  • douhuai4155 2017-03-10 05:30

    You could also serialize all the inputs of the current form and run through each one like this :

    $('.commentform').on('submit', function(e){
        var formInputs = jQuery(this).serializeArray();
        jQuery.each(formInputs, function(i, field){
            console.log( + " : " + field.value);
    打赏 评论

相关推荐 更多相似问题