【问题标题】:problem with jquery dialogjquery对话框的问题
【发布时间】:2009-11-03 04:13:51
【问题描述】:

我有一个带有下拉菜单(Paid and unpaid 作为选项)和一个按钮的局部视图。 当用户在页面的子菜单中单击Paid/Unpaid List link 时,我正在使用 jquery 加载加载此部分视图。

当我在下拉菜单中选择付费并单击按钮时,它会在 jquery 对话框中显示付费客户列表,如果我选择未付费并单击按钮,它会在 jquery 对话框中显示未付费客户。

我正在为对话框编写以下代码:

 $('#customers').dialog({
            bgiframe: true,
            autoOpen: false,
            open: function(event, ui) {
                //populate table
                var p_option = $('#d_PaidUnPaid option:selected').val();
                if (p_option  == 'PAID') {
                    $("#customercontent").html('');
                    //$("#customercontent").load("/Customer/Paid");
                }
                else if (p_option  == 'UNPAID') {
                    $("#customercontent").html('');
                    //$("#customercontent").load("/Customer/Unpaid");
                }
            },
            close: function(event, ui) {
                //do nothing
            },
            height: 500,
            width: 550,
            modal: true
        });

我第一次在 jquery 对话框中正确获取列表,但是当我再次单击 Paid/Unpaid List link 并在下拉列表中选择 Unpaid 并单击按钮时,它会在 jquery 对话框中显示 previos 加载的内容。

我在这里做错了什么?

【问题讨论】:

    标签: jquery asp.net-mvc dialog load


    【解决方案1】:

    尝试向 jQuery AJAX 添加无缓存选项。我在总是显示缓存结果的 load() 函数(和 IE)上遇到问题。 要更改所有 jQuery AJAX 请求的设置,请执行

    $.ajaxSetup({cache: false});
    

    【讨论】:

    • 我应该在哪里添加这一行?在加载部分视图之前? ——
    • 甚至在 $('#customers').dialog({...
    • 我在打开对话框之前已经调用了按钮的点击事件,但是问题还是出现了
    • 这里是$(document).ready中添加的按钮的点击事件: $('#b_customers').click(function(e) { $.ajaxSetup({ cache: false }) ; $('#customers').dialog('open'); });
    【解决方案2】:

    我希望我想出正确答案还为时不晚。我遇到了同样的问题,我通过以下 ajax 设置解决了它。

    open: function () {
          jQuery.ajaxSetup({
                 cache: false
           });
           //populate table or do what you want...
    }
    

    【讨论】:

      【解决方案3】:

      尝试打开后添加这个:

      $('#customers').empty().remove();
      

      例子:

          open: function(event, ui) {
                    //populate table
                    var p_option = $('#d_PaidUnPaid option:selected').val();
                    if (p_option  == 'PAID') {
                        $("#customercontent").html('');
                        //$("#customercontent").load("/Customer/Paid");
                    }
                    else if (p_option  == 'UNPAID') {
                        $("#customercontent").html('');
                        //$("#customercontent").load("/Customer/Unpaid");
                    }
      
                    $('#customers').empty().remove();
      
                },
      

      【讨论】:

        猜你喜欢
        • 2011-05-28
        • 2011-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-24
        相关资源
        最近更新 更多