如何访问$(this)里面的甜警报,里面的AJAX成功
how to access the $(this) inside sweet alert, inside AJAX success
我想删除被点击元素的父元素。我首先使用甜蜜警报来获取警报,然后在调用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')
我在jQuery中遇到了同样的问题。主要的问题是ajax不能直接访问这个上下文。因此,我们需要将这个上下文传递给ajax。首先,我们将上下文存储在一个变量中,然后将该上下文赋值到ajax中。
$(".delete_category").click(function () {
var call_url = $(this).val();
var this_context = $(this);
swal({
title: "Are you sure?",
text: "Your may not be able to recover!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
},
function () {
$.ajax({
context: this_context,
method: "POST",
url: call_url,
success: function (response) {
if (response == "success") {
swal("Deleted!", "Record deleted successfully.", "success");
$(this).closest('.delete_row').hide();
} else {
swal("Error!", response, "error");
}
}
});
}
);
});
相关文章:
- 在ajax成功后,cluetip不适用于首次点击活动元素
- jQuery成功函数中的ajax成功函数
- jQuery触发器点击未从AJAX成功工作
- 如何使用jQuery可编辑插件检查ajax是否成功完成
- 执行ajax成功函数-jQUERY
- 如何从servlet获取数据到ajax成功
- ajax请求成功,但可以'我看不到我的数据
- 通过mvc中的ajax动作链接获取关于成功的响应头
- AJAX调用在chrome扩展中未成功
- Ajax正确发布表单,但不会返回成功数据
- Ajax没有't执行成功函数
- JQuery FullCalendar在从ajax成功调用rerenderEvents时遇到问题
- 为什么Jquery$.ajax在函数调用中触发所有statusCode,即使调用成功
- ajax成功地将数组中的数据放入表中各自的输入中
- 在成功时操作 AJAX 函数
- Backbone fetch中的Ajax在fetch调用退出后完成,因此fetch调用中没有成功/失败事件
- 如何从ajax成功回调函数中读取javascript变量
- 成功ajax:如果是200状态代码,则运行函数else另一个函数
- 当移动到“外部”版本时,“内部”成功 AJAX 中的“数据”变量应该更改为什么
- 如何获得变量警报(测试)从var测试成功ajax