我有这些复选框:如何发送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