【问题标题】:jquery dialogue destroy syntaxjquery 对话破坏语法
【发布时间】:2015-06-10 16:27:19
【问题描述】:

我有一个加载局部视图的对话框,从我的 MVC 4 应用程序中的多个不同视图调用。它有一个文本区域和一个关于文本区域中剩余多少字符的小通知。在页面加载时一切正常,但是当对话框关闭时,无论是通过发送按钮还是对话框标题栏中的关闭按钮,当它重新打开时,'#textarea_feedback' div 内容会消失,直到页面重新加载。我相信我应该使用 dialog('destroy') 但似乎无法正确使用语法。它要么没有效果,要么在页面底部显示部分视图。请告知,希望我已经包含了足够的代码来识别问题。谢谢

   $(document).ready(function () {
    var text_max = 160;
    $('#textarea_feedback').html(text_max + ' characters remaining');
    $('#txtMessage').keyup(function () {
        var text_length = $('#txtMessage').val().length;
        var text_remaining = text_max - text_length;
        $('#textarea_feedback').html(text_remaining + ' characters remaining');
    });


    $('#send').click(function (e) {
        if ($('#txtSMSMessage').val().trim()) {
            e.preventDefault();
            $.ajax({
                type: "POST",
                data: $('form#Composer').serialize(),
                url: '/MyController/MyAction',
                success: function (data) {
                    alert('Sent');
                    $('#Composer').closest("div.ui-dialog-content").dialog("close");
                },
                error: function (a, b, c) {
                    $("#Composer").unblock();
                    alert(b);
                }
            });
            //$('#Composer').closest("div.ui-dialog-content").dialog("destroy");
        }
    });

    //var dialog = $('#Composer').closest("div.ui-dialog-content").dialog();
    //console.debug(dialog);
    //dialog.on("dialogbeforeclose", function (event, ui) {
    //    dialog.dialog('destroy')
    //});

});

【问题讨论】:

标签: javascript jquery ajax jquery-ui asp.net-ajax


【解决方案1】:

想发布答案以防它可以帮助其他人,真的是 LShetty 的评论让我朝着正确的方向前进。添加到创建对话框的 Ajax 调用的 CLOSE 函数中:

    $.ajax({
    url: 
      ...
    type: "POST",
    success: function (responseText, textStatus, XMLHttpRequest) {
        dialog.html(responseText);
        dialog.dialog({
            ...
            title: 'Send message',
            open: function () {
               ...
            },
            close: function () {
                $(this).dialog('destroy').remove()
            },
            ...
        });
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-29
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多