2011-02-23 25 views
1

我試圖設置一個接口,其中有一個窗體包含關於一些jQuery UI選項卡的過濾器。這些標籤通過ajax加載。問題與jQuery UI標籤(通過ajax加載)和表單數據

當我點擊其中一個選項卡時,我希望表單中的數據被提交到該選項卡。

我設置了ajaxOptions以從我的表單中獲取數據,將其序列化並將其發佈到url。我將緩存關閉,並且我關閉了ajaxOptions的緩存。

這是我用來設置選項卡的代碼。

$("#schedule-tabs").tabs({ 
ajaxOptions: { 
        type: 'POST', 
        data: $('#filters').serialize(), 
        cache: false, 
        error: function(xhr, status, index, anchor) { 
           $(anchor.hash).html("<p>An error has been encountered while attempting to load this tab.</p>"); 
          } 
       }, 
cache:   false 
}); 

當標籤負載,即沿傳遞的數據是在窗體時首次加載頁面,即使我在形式已經改變了過濾器的數據。

我已加入下列到上述標籤安裝到驗證表單數據沿途:

select: function(event, ui) { 
     alert($('#filters').serialize()); 
    }, 
load: function(event, ui){ 
      alert($('#filters').serialize()); 
     }, 

show: function(event, ui){ 
      alert($('#filters').serialize()); 
     } 

在所有3個實例,更新的形式的數據被提醒。但是,當數據到達我的頁面時,它是原始數據而不是新數據。

看來某物正在某處被緩存,但我不知道在哪裏。

不應該從每個ajax頁面加載的表單中抓取新的數據嗎?爲什麼被緩存?有沒有其他方式可以覆蓋標籤內容加載時發佈的數據?

這是我目前項目中的一個巨大阻滯器。如果我不能很快解決它,我將不得不尋找除了jQuery UI選項卡以外的其他解決方案。我想使用它們,但如果這個問題不能解決...

任何人都可以幫助嗎?

回答

3

我相信我已經想出了我自己的問題的答案。我想分享以防其他人遇到同樣的情況。

基本上,我添加了一個選項,當選中選項卡時,它將獲取當前表單數據並重置ajaxOptions。

我現在使用的代碼是:

// set up the jQuery UI Tabs 
var $tabs = $("#schedule-tabs").tabs({ 
    ajaxOptions: { 
         type: 'POST', 
         data: $('#filters').serialize(), 
         cache: false, 
         error: function(xhr, status, index, anchor) { 
            $(anchor.hash).html("<p>An error has been encountered while attempting to load this tab.</p>"); 
           } 
        }, 
    cache:   false, 
    select:   function(event, ui) { 
         // get the current form data 
         var filter_options = $('#filters').serialize(); 
         // update the data for the ajax options 
         $(this).tabs('option', 'ajaxOptions', { type: 'POST', 'data': filter_options }); 
         return true; 
        } 
}); 

我希望這可以幫助別人了。