在 jQuery UI AJAX 加载的选项卡上传递变量

发布于 2024-12-05 21:18:13 字数 1210 浏览 0 评论 0原文

我在使用 PHP 和 jQuery 构建的在线应用程序上遇到了一个独特的 UI 问题。该页面由 jQuery UI 选项卡组成,通过 ajax 方法加载数据。从呈现选项卡的 index.php 开始,用户可以打开 jQuery UI 对话框模式窗口来选择用户。选择用户后(通过其姓名旁边的链接),函数应关闭对话框窗口,选择选项卡索引 #1,并为已加载的页面提供一个变量,以允许我运行填充用户数据的查询在该页面中。

一切都运行良好,但最后一部分......我无法将变量传递到页面来挽救我的生命。

首先,设置:

<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>

我尝试了几种不同的方法,包括通过“Ajax选项”字段传递ajax参数 如此处所述 这似乎是理想的解决方案,但无论我做什么,似乎都无法通过 currentcall.php 获取 $_REQUEST 参数。我不能仅仅通过函数中的 $('#id').val() 在 currentcall.php 中设置隐藏变量,因为选项卡将打开的页面尚未被设置尚未加载到 DOM 中。我不知道从这里该去哪里!

I've got a unique UI issue on an online application built with PHP and jQuery. The page is made of jQuery UI tabs which load data via the ajax method. Starting on the index.php where the tabs are rendered, the user is allowed to open a jQuery UI dialog modal window to select a user. Upon choosing a user (via a link next to their name) a function should close the dialog window, select tab index #1, and make a variable available to the page that's loaded to allow me to run a query that will populate the user data in that page.

All is working well but the last part....I can't get a variable to the page to save my life.

First, the setup:

<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>

I've tried several different methods including passing ajax parameters via the "Ajax Options" field as described here which seems like the ideal solution, but no matter what I do it seems I can't get a $_REQUEST parameter through to currentcall.php. I can't just set a hidden variable in the currentcall.php via $('#id').val() in the function, because the page that will be opened by tabs hasn't been loaded into the DOM yet. I'm at a loss where to go from here!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姐不稀罕 2024-12-12 21:18:13

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>

In the ajaxOption solution you need to use a function so that it is re-evaluated each time the ajax call is being made..

use

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文