How to send serialize form data using JQuery if the input element is an array

后端 未结 14 672
庸人自扰
庸人自扰 2020-12-16 15:16

I have this piece of code in my PHP code:

while ($row = mysqli_fetch_assoc($result))
{
    extract($row);
    echo \"\";
    echo \"

        
14条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 15:50

    var arTags = new Array();
    
    jQuery.map( $("input[name='tags[]']") , function(obj,index)
    {
       arTags .push($(obj).val());
    });
    
    var obj = {'new_tags'           : $("#interest").val() ,
               'allready_tags[]'  : arTags };
    
    var post_data = jQuery.param(obj,true);
    
    $.ajax({
          type :  'POST',
          url  :  'some_url',
          data :  post_data,
          dataType : "html",
          success: function(htmlResponse)
          {
    
          }
    });
    

提交回复
热议问题