在嵌套 ajax“成功”函数中引用 $(this) 时出现问题...我知道这是一个范围问题,但似乎无法找到一种干净的方法来在成功更新时关闭对话框。感谢您的帮助。
$("#dialog_support_option_form").dialog({
width: 400,
height: 180,
bgiframe: true,
autoOpen: false,
modal: true,
buttons: {
'Save Support Option': function(){
$.ajax({
type: 'POST',
url: "support_options/create_support_option.php",
data: $(this).find('form').serialize(),
success: function(data){
$("#list_support_options").html(data);
$(this).dialog('close');
}
});
},
'Cancel': function(){
$(this).dialog('close');
}
},
close: function(){
$(this).find('input').val('');
}
});
最佳答案
您应该使用 ajax 选项 context: $(this),
设置所选元素的回调范围。
关于JQuery UI 对话框 - 成功时 Ajax 更新 $(this).dialog ('close' );,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2585756/