我有一个使用while循环创建,当用户点击删除按钮AJAX用于删除数据库中的条目,并重绘列表清单。这一切都正常工作,直到用户试图删除另一个项目,该按钮什么也不做,没有错误,唯一的方法是刷新页面。AJAX创建的窗体不会触发Ajax调用
我已经改变了AJAX因此所有的返回是同一类作为原始的按钮,看看我至少可以得到,如果没有别的它来触发警报,但没了,什么都没有。
的AJAX
<script type="text/javascript">
$(document).ready(function() {
$('.trash_btn').click(function(){
alert('bob');
var question = $(this).next('.id_question').val();
var user = '<? echo $id; ?>';
alert(question+' '+user);
$.msgbox("Are you sure you want to delete the selected question?", {
type: "error",
buttons: [
{type: "submit", value: "Yes"},
{type: "cancel", value: "No"}
]
}, function(result) {
if (result == 'Yes') {
$.ajax({
url: 'ajax/opinion_del.php',
type:'POST',
data: 'question='+ question +'&user='+user,
success: function(response){
$('#responses_table').html(response);
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
} // End of success function of ajax form
});
}
});
});
});
</script>
表的相关部分
<td class="details">
<input type="button" name="del_question" value="" class="trash_btn">
<input type="hidden" class="id_question" name="question_id" value="<? echo $row['questionID']; ?>">
<input type="hidden" class="id_user" name="user" value="<? echo $id; ?>" >
</td>
AJAX输出创建非工作测试按钮(最初是使用JSON但修剪出来用于测试)
$smeg = '<input type="button" value="test" class="trash_btn">';
echo $smeg;
完美!谢谢 – tatty27