我有这些复选框:
<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); } );但样式[]不会发送...
编辑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()它发送这个(在提琴手上检查)
style: style%5B%5D=Style1&style%5B%5D=Style3&style%5B%5D=Style4不是:
style[]: Style1 style[]: Style3 style[]: Style4最后一个是真正的/全面的HTML数组...
I have these checkboxes :
<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" />and this jquery handler :
<script type="text/javascript"> $(document).ready(function() { $('.linkStyle').click(function(e) { // }); }); </script>so, when I click on a checkbox, I'd like to send the array style[] to the server trought AJAX (with the actual values).
How can I do it?
EDIT
Tried :
$.post("list/browse_ajax.php", {id:"browseUpdate", actualArtist:browseArtist, actualEvent:browseEvent, actualData:browseData, style:$('#browseTableStyle:checkbox').serialize()}, function(data) { $("#browseList").html(data); } );but the style[] is not send...
EDIT 2 - Problem with serialize
This is the whole code :
<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>but with :
style:$('#browseForm').serialize()it sends this (checked on Fiddler)
style: style%5B%5D=Style1&style%5B%5D=Style3&style%5B%5D=Style4not :
style[]: Style1 style[]: Style3 style[]: Style4The last is a real/comprensive HTML array...
最满意答案
当你finnaly有你的字符串提交style%5B%5D=Style1&style%5B%5D=Style3&style%5B%5D=Style4你可以像这样检索全面的数组:
parse_str($_POST['style'], $data);$data变量包含:
array( "style" => array( 0 => "Style1", 1 => "Style3", 2 => "Style4", ) )它能解决你的问题吗?
When you finnaly have your string submitted style%5B%5D=Style1&style%5B%5D=Style3&style%5B%5D=Style4 you can retrieve the comprehensive array like that:
parse_str($_POST['style'], $data);The the $data variable contains:
array( "style" => array( 0 => "Style1", 1 => "Style3", 2 => "Style4", ) )Does it solve your problem ?
更多推荐
发布评论