0
对于表中的每一行,提交按钮的以下表单正在被回显。使用相同的ajax的多个提交
echo '<form method="POST" name="implement" id="implement" action="submit.php?data='.$data.'" style="display: inline;">
<input type="submit" name="submit" value="Implement">
</form>';
每个提交按钮必须能够使用下面的javascript。我无法弄清楚如何为每个表单分配一个唯一的ID。
<script>
$(function(){
$('#implement).on('submit', function(e){
// prevent native form submission here
e.preventDefault();
// now do whatever you want here
$.ajax({
type: $(this).attr('method'), // <-- get method of form
url: $(this).attr('action'), // <-- get action of form
data: $(this).serialize(), // <-- serialize all fields into a string that is ready to be posted to your PHP file
beforeSend: function(){
$('#result').html('');
},
success: function(data){
$('#result').html(data);
if(data === "0") {
alert("label1");
}
if(data === "1") {
alert("label2");
}
}
});
});
});
</script>
你可以通过班级而不是Id或者'form'来完成。 – Rasclatt