我很难提交此表格:
<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...
}
});
});
但是当我点击一个复选框时没有任何反应。我怎样才能解决这个问题?
更新: 值得一提的是,该表单位于引导模式中。
原文由 Karlom 发布,翻译遵循 CC BY-SA 4.0 许可协议
您缺少
data
属性。有关示例,请参阅: JQuery $.ajax() post - java servlet 中的数据。
如果你想发送表单的内容,那么你可以使用
Form.serialize()
,但你可以将任何你想要的数据放入属性中。