親愛なるstackoverflowers、
特定のフィールドの ID と値の取得について質問があります。現在、次のコードがあります。
<div class="category_edit_form">
<input type = "text" name = "category_edit_text" class = "category_edit_text" id = "'.$category->category_id.'">
<input type = "button" class="category_edit_button" value = "Wijzig">
</div>
これは foreach ループの出力です。したがって、表示される各カテゴリには、名前を変更するためのテキストフィールドとボタンがあります。これは私のjQueryです:
jQuery(".category_edit_button").click( function() {
jQuery.ajax({
async: false,
url: nieuwsbrief.updatecategory,
type: 'POST',
data: { category_id: jQuery('.category_edit_text').prop('id'), category_name: jQuery('.category_edit_text').val()},
success: function(data) {
alert(data);
}
});
});
警告するデータは次のとおりです。
echo $_POST['category_id']."en de naam is: ".$_POST['category_name'];
しかし、ボタンをクリックするたびに、最初のフィールドの値と id しか表示されません。したがって、2 番目のテキスト フィールドのボタンをクリックすると、2 番目のテキスト フィールドの ID と値の代わりに、最初のフィールドの ID と値がポップアップ表示されます。
どうすればこの問題を解決できますか?