2009-11-03 110 views
5

我有一個下拉(與Paid and unpaid作爲選項)和一個按鈕的局部視圖。 當用戶在頁面的子菜單中單擊Paid/Unpaid List link時,我使用jquery load加載此部分視圖。問題與jQuery對話框

當我在下拉菜單中選擇付費並點擊按鈕時,它會在jquery對話框中顯示付費客戶列表,如果我選擇Unpaid並單擊按鈕,它會在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和選擇下拉未付並點擊按鈕,它會在jquery對話框中顯示previos加載的內容。

我在這裏做錯了什麼?

回答

4

嘗試在jQuery AJAX中添加no-caching選項。 load()函數(和IE)遇到問題,緩存的結果將始終顯示。 要更改設置,用於所有的jQuery AJAX請求做

$.ajaxSetup({cache: false}); 
+0

我應該在哪裏添加這一行?加載部分視圖之前? - – Prasad 2009-11-03 04:39:14

+0

甚至在$('#customers')。對話框({...應該足夠了。如果你有任何類型的javascript bootstrap文件,那就是它通常會去的地方 – 2009-11-03 04:42:57

+0

我之前在button的click事件中調用過打開對話框,但問題仍然存在 – Prasad 2009-11-03 04:48:28

1

嘗試加入這個開放後:

$('#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(); 

      }, 
3

我希望我不是太晚拿出正確答案。我遇到了同樣的問題,我用下面的ajax設置解決了它。

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

這對我有效......這不是有趣的追蹤。 – 2011-06-03 03:14:01