2011-01-20 21 views
1

複数の選択要素の中に日付のリストがあり、選択した日付のリストをサーバーに送信して処理する必要があります。
jQueryはメモリとCPUの両方の使用量が連続的に増えていますが、haywireパーツを単独で実行しても問題ありません。リストを送信する:複数の選択可能な選択から選択します。getJSON

HTML 
<select id="my-dates" name="my-dates[]" multiple="multiple" size="5"> 
    <option>2011-01-18</option> 
    <option>2011-01-20</option> 
    <option>2011-01-21</option> 
    <option>2011-01-27</option> 
</select> 

jQuery 
$.getJSON('dates_handling.php',{ 
dates: $('select#my-dates').find(':selected'), 
other:stuff 
},function(result){ 
    // result handling 
}); 
data key 'dates' should contain an transmit-able array like ['2011-01-20',2011-01-27'] 

jQuery haywire part 
$('select#my-dates').find(':selected') 

答えて

1

フルjQueryのオブジェクトを渡しているので、私は手動で日付配列を構築したい:

あなたが使用することもでき
var selectedDates = []; 

$('select#my-dates > option:selected').each(function() { 
    selectedDates.push($(this).html()); 
}); 

$.getJSON('dates_handling.php',{ 
dates: selectedDates, 
other:stuff 
},function(result){ 
    // result handling 
}); 
+0

これは機能します。 .each()の代わりに.map()を使用しました。 – Kim

0

$('#my-dates').val() 

それは配列として選択された値を返します。 。

関連する問題