send an array of values through a ajax post

2020-06-27 09:30发布

问题:

Please consider the following code,

<form action="index.php" method="post" name="adminForm" enctype="multipart/form-data">        
     <input type="hidden" name="showtime[]" id="showtime_1" value="1" />
     <input type="hidden" name="showtime[]" id="showtime_2" value="2" />
     <input type="hidden" name="showtime[]" id="showtime_3" value="3" />

     <input type="hidden" name="mid" id="movie_id" value="100" />
     .
     .
     .
</form>

I want to use ajax post to submit this.

$.post('index.php',{
                    'option':'com_movies',
                    'controller':'movie',
                    'task' : 'savedata',
                    'format':'raw',            
                    'mid':$('#movie_id').val()           
            },function(result){           
              if(result)                      
                  alert(result);           
                return;
            });

I want to know how I send showtime ids using ajax post.

回答1:

You can use

$('input[name="showtime[]"]').serialize()

Which will give you all inputs with showtime name in format you can send by ajax...

Check on jsfiddle...

Demo