2011-09-20 80 views
2

我在使用PHP和jQuery構建的在線應用程序上遇到了獨特的UI問題。該頁面由通過ajax方法加載數據的jQuery UI選項卡組成。從呈現選項卡的index.php開始,允許用戶打開一個jQuery UI對話框模式窗口來選擇用戶。在選擇一個用戶時(通過他們名字旁邊的鏈接),一個函數應該關閉對話窗口,選擇標籤索引#1,併爲加載的頁面創建一個變量,以允許我運行一個查詢來填充用戶數據在該頁面中。在jQuery UI上傳遞變量AJAX加載標籤

所有的工作都很好,但最後一部分....我無法獲得一個變量來保存我的生活頁面。

首先,設置:

<ul> 
<li><a href="dashboard.php">Dashboard</a></li> 
<li><a href="currentcall.php">Current Call</a></li> 
<li><a href="managequeue.php">Manage Queue</a></li> 
<li><a href="admin.php">Admin</a></li> 
</ul> 

<script type="text/javascript"> 
    var curtab = $('#tabs').tabs(); 

    function chooseSearchProspect(prospect_id, allow_open) { 
     $('#prospect_search_modal').dialog('close'); 
     $("#tabs").tabs({ 
     disabled: [], 
     selected: 1, 
     }); 
    } 
</script> 

我試過幾種不同的方法,包括通過「阿賈克斯選項」字段as described here這似乎是理想的解決方案通過AJAX的參數,但無論我做什麼,似乎我無法通過currentcall.php獲取$ _REQUEST參數。我不能在函數中通過$('#id').val()在currentcall.php中設置隱藏變量,因爲將由標籤打開的頁面尚未加載到DOM中。我不知道該從哪裏出發!

回答

4

ajaxOption解決方案,您需要使用的功能,使其Ajax調用正在取得每​​次重新評估..

使用

<script type="text/javascript"> 

    var variable_to_pass = 0; // your global variable; 
    function getVariable(){return variable_to_pass;} 

    var curtab = $('#tabs').tabs({ 
         ajaxOptions: { data: { variable_used_in_php: getVariable } } 
       }); 

    function chooseSearchProspect(prospect_id, allow_open) { 
     $('#prospect_search_modal').dialog('close'); 
     variable_to_pass = 1;// set it to whatever you want to pass to the ajax call.. 
     $("#tabs").tabs({ 
     disabled: [], 
     selected: 1 
     }); 
    } 
</script> 
+0

真棒......偉大的工作。我認爲最終導致我嘗試失敗的原因是我在文檔就緒函數中聲明瞭我的變量,然後嘗試在文檔之外運行chooseSearchProspect函數,這意味着該變量超出了範圍。 – bpeterson76