我很难提交此表:如何通过jquery ajax提交复选框?
<form action="/someurl" method="post">
<input type="hidden" name="token" value="7mLw36HxPTlt4gapxLUKWOpe1GsqA0I5">
<input type="checkbox" class="mychoice" name="name" value="apple"> Apple
<input type="checkbox" class="mychoice" name="name" value="orange"> Orange
<input type="checkbox" class="mychoice" name="name" value="pear"> Pear
</form>
而jQuery的位:
$('.mychoice').click(function() {
$.ajax({
url: '/someurl',
type: 'post',
dataType: 'json',
success: function(data) {
// ... do something with the data...
}
});
});
但是当我点击一个复选框,没有任何反应。我怎样才能解决这个问题?
更新:值得一提的是表单位于bootstrap模式。
你什么时候运行jQuery代码? –
它应该在引导模式下运行。 – Karlom
当你的代码运行时,你确定你的元素在DOM中吗?你能发布一个片段的例子吗? –