Jquery 在Ajax请求帖子中序列化特定表单
我有一张书桌,每行都有书号,还有书名和删除按钮,可以删除这本书 我正在使用ajax进行删除,当我单击delete按钮时遇到的问题是,它总是删除表中的第一本书,任何帮助,谢谢Jquery 在Ajax请求帖子中序列化特定表单,jquery,django,ajax,Jquery,Django,Ajax,我有一张书桌,每行都有书号,还有书名和删除按钮,可以删除这本书 我正在使用ajax进行删除,当我单击delete按钮时遇到的问题是,它总是删除表中的第一本书,任何帮助,谢谢 <table> <thead> <tr> <th>Book NO</th> <th>Book Name</th> <th>Remove</th> </tr> </thea
<table>
<thead>
<tr>
<th>Book NO</th>
<th>Book Name</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
{% for book in book_List %}
<tr>
<td>{{book.no}}</td>
<td>{{book.name}}</td>
<td>
<form method="POST">
<input type="hidden" name="remove_uuid" value="{{ book.uuid}}">
<button onclick="delete()">Delete</button>
</form>
</td>
</tr>
{%endfor%}
</tbody>
</table>
您通过标记名$('form').serialize()从中获取。这是它获取表中第一个表单的方式,因此您可以执行target.form
function delet(){
form = event.target.form;
$.ajax({
type:'POST',
data: $(form).serialize(),
success: function (data) {
alert("the book has been delete it")
}
}
您通过标记名$('form').serialize()从中获取。这是它获取表中第一个表单的方式,因此您可以执行target.form
function delet(){
form = event.target.form;
$.ajax({
type:'POST',
data: $(form).serialize(),
success: function (data) {
alert("the book has been delete it")
}
}
使用$(表单).serialize(),
在这个console.log(form)之前使用$(form.serialize(),
在console.log(表单)之前