2012-01-26 58 views
2

請考慮下面的代碼發送值的數組,通過AJAX後

<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> 

我想用ajax後提交此。

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

我想知道如何使用ajax post發送showtime id。

回答

5

您可以使用

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

,這將給你在格式欣欣的名字所有輸入則可以通過AJAX發送...

檢查的jsfiddle ...

Demo

+1

謝謝它的工作原理。 – Sara