1
クリックした要素の親を削除します。私は、最初の警告を取得するために甘いアラートを使用して、私は、AJAX機能を呼び出すと、私は成功機能で要素を取得したい後:
これは私の関数である:
function removeImage(id) {
var element = $(this).closest('.dropzone');
swal({
title:"Delete",
text: "delete",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes !",
cancelButtonText: "No, cancel",
closeOnConfirm: false, closeOnCancel: false
}, function(isConfirm){
if (isConfirm) {
$.ajax({
type: "POST",
data: {id: id},
url:'ajax/deleteimage.php',
success : function(data){
if(data == 'ok'){
swal({
title:"Delete",
text: "delete",
type: "success",
confirmButtonColor: "#AEDEF4",
confirmButtonText: "Ok",
closeOnConfirm: true,
}, function(isConfirm){
$.when($('.dropzone').find("#"+id).parent().fadeOut())
.done(function() {
$('.dropzone').find("#"+id).parent().remove();
});
var n_div = $('.dz-image-preview').length-1;
if (n_div === 0) {
$('.dz-message').css("opacity",'1');
}
});
}else{
swal("Error, try again", "", "error");
}
}
}); // end ajax call
} else {
swal("Cancel", "", "error");
}
});
}
私は変更することはできません。変数要素を含む成功関数内の$('.dropzone')
。
の可能性のある重複した[コールバック内の正しい\ 'この\' /コンテキストにアクセスする方法?](http://stackoverflow.com/questions/20279484/how-to-access-the-correct- this-context-inside-a-callback) –
クリックされた要素が何であるかは不明です。関数は 'id'を受け取りますが、関数がクリックハンドラであるかのように、' this'を使用しようとします。 –
関数がどのように呼び出されるかを示すのに役立ちます。 –