我有這些複選框:如何發送HTML陣列trought AJAX
<input type="checkbox" name="style[]" value="1" checked="checked" />
<input type="checkbox" name="style[]" value="2" />
<input type="checkbox" name="style[]" value="3" checked="checked" />
<input type="checkbox" name="style[]" value="4" checked="checked" />
<input type="checkbox" name="style[]" value="5" />
與這個jQuery處理程序:
<script type="text/javascript">
$(document).ready(function() {
$('.linkStyle').click(function(e) {
//
});
});
</script>
所以,當我點擊複選框,我想送數組樣式[]給服務器帶來了AJAX(帶有實際值)。
我該怎麼辦?
編輯
嘗試:
$.post("list/browse_ajax.php", {id:"browseUpdate", actualArtist:browseArtist, actualEvent:browseEvent, actualData:browseData, style:$('#browseTableStyle:checkbox').serialize()},
function(data) {
$("#browseList").html(data);
}
);
但款式[]不發...
EDIT 2 - 與序列化問題
這是整個代碼:
<form id="browseForm">
<div class="wideinfo">
<div class="content">
<div class="tableList1">
Style
</div>
<div class="tableList2">
<span><input type="checkbox" name="style[]" value="Style1" checked="checked" /> Style1</span>
<span><input type="checkbox" name="style[]" value="Style2" /> Style2</span>
<span><input type="checkbox" name="style[]" value="Style3" checked="checked" /> Style3</span>
<span><input type="checkbox" name="style[]" value="Style4" checked="checked" /> Style4</span>
<span><input type="checkbox" name="style[]" value="Style2" /> Style5</span>
</div>
</div>
</div>
</form>
但:
style:$('#browseForm').serialize()
它發送這個(上的Fiddler選中)
style: style%5B%5D=Style1&style%5B%5D=Style3&style%5B%5D=Style4
不:
style[]: Style1
style[]: Style3
style[]: Style4
最後是一個真正的/ comprensive HTML陣列.. 。
是的,男人,也許......但爲什麼我應該這樣做,如果我能以正確的形式發送數據? :)這就是我的意思,用Fiddler分析:http://img854.imageshack.us/f/examplek.jpg/(用標準提交/發送與該功能發送) – kwichz 2011-05-03 15:18:51
胡,我現在看得更清楚。這就是爲什麼你應該把所有東西都放在形式上,並且把所有的東西都整合起來。這樣你就不會有這個問題。另一種方法是有一個非常沉重的JS手動提取所有的數據。 – 2011-05-03 15:22:27
我發現如何解決它:)只是我創建一個字符串爲style ='style [] = Acid&style [] = Ambient&style [] = Big + Beat';我發送它:) – kwichz 2011-05-03 20:16:24