JQuery UI对话 - 成功的Ajax更新$(this).dialog('close');

ube*_*zik 11 jquery user-interface jquery-ui-dialog

从嵌套的ajax'success'函数中引用$(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('');
        }
    });
Run Code Online (Sandbox Code Playgroud)

Jon*_*ian 21

您应该使用ajax选项context: $(this),将回调的范围设置为所选元素.