遇到问题。 我显示的每个图像都包含两个不同的按钮。 一个是删除,另一个被指定为"主要"。
删除作品。 它隐藏图像,删除文件和MySQL行。
分配主要作品类型。 它更新数据库中的行,将"main"值更改为 1,因为它应该,但是,它也应该 alert(),但它没有。
<script>
$(document).ready(function() {
$(".remove_image").click(function() {
var image_id = $(this).attr('id');
$.ajax({
type:"post",
url:"imagecontrol.php",
data: { image_id:image_id,
image_remove:1},
success: function(response) {
$('#image_'+image_id).fadeOut(400);
showUploader();
}
})
})
});
$(document).ready(function() {
$(".assign_main").click(function() {
var assign_this_id = $(this).attr('id');
$.ajax({
type:"post",
url:"imagecontrol.php",
data: { assign_this_id:assign_this_id,
image_assign:1},
success: function(response) {
alert("Success");
}
})
})
});
</script>
仅在返回HTTP 200
或HTTP 304
时调用 success
方法,因此您可能需要仔细检查是否确实如此。
这可以在大多数现代网络浏览器的"检查器"面板中完成,通常在"网络"选项卡下。
您还可以添加 error: function() {}
事件处理程序来捕获任何 HTTP 4xx/5xx 代码。
尝试提醒肯定存在的错误:
$(document).ready(function() {
$(".assign_main").click(function() {
var assign_this_id = $(this).attr('id');
$.ajax({
type:"post",
url:"imagecontrol.php",
data: { assign_this_id:assign_this_id,
image_assign:1},
success: function(response) {
alert("Success");
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus + " " + errorThrown);
}
})
})
});
这将显示您的PHP代码中是否有问题
使用 done()
代替它:
$.ajax({
type: "post",
url: "imagecontrol.php",
data: {
image_id: image_id,
image_remove: 1
}
}).done(function(response) {
$('#image_' + image_id).fadeOut(400);
showUploader();
);