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