1. <legend id='MJNwf'><style id='MJNwf'><dir id='MJNwf'><q id='MJNwf'></q></dir></style></legend>
  2. <tfoot id='MJNwf'></tfoot>
      <bdo id='MJNwf'></bdo><ul id='MJNwf'></ul>
    <i id='MJNwf'><tr id='MJNwf'><dt id='MJNwf'><q id='MJNwf'><span id='MJNwf'><b id='MJNwf'><form id='MJNwf'><ins id='MJNwf'></ins><ul id='MJNwf'></ul><sub id='MJNwf'></sub></form><legend id='MJNwf'></legend><bdo id='MJNwf'><pre id='MJNwf'><center id='MJNwf'></center></pre></bdo></b><th id='MJNwf'></th></span></q></dt></tr></i><div id='MJNwf'><tfoot id='MJNwf'></tfoot><dl id='MJNwf'><fieldset id='MJNwf'></fieldset></dl></div>

      <small id='MJNwf'></small><noframes id='MJNwf'>

      如何将数组传递给 Drupal 菜单回调

      时间:2023-06-22

    1. <legend id='UXstz'><style id='UXstz'><dir id='UXstz'><q id='UXstz'></q></dir></style></legend>
        <tfoot id='UXstz'></tfoot>

            <tbody id='UXstz'></tbody>
            <bdo id='UXstz'></bdo><ul id='UXstz'></ul>
              • <small id='UXstz'></small><noframes id='UXstz'>

              • <i id='UXstz'><tr id='UXstz'><dt id='UXstz'><q id='UXstz'><span id='UXstz'><b id='UXstz'><form id='UXstz'><ins id='UXstz'></ins><ul id='UXstz'></ul><sub id='UXstz'></sub></form><legend id='UXstz'></legend><bdo id='UXstz'><pre id='UXstz'><center id='UXstz'></center></pre></bdo></b><th id='UXstz'></th></span></q></dt></tr></i><div id='UXstz'><tfoot id='UXstz'></tfoot><dl id='UXstz'><fieldset id='UXstz'></fieldset></dl></div>
                本文介绍了如何将数组传递给 Drupal 菜单回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在 JavaScript 中有两个数组:var xcoord = [];var ycoord = [];经过一些处理,每个数组包含 15 个数值.我想将此数据发送到 Drupal 中的菜单回调.

                I have two arrays in JavaScript: var xcoord = []; and var ycoord = []; After some processing, each array contains 15 numeric values. I'd like to send this data to a menu callback in Drupal.

                我的 AJAX 代码:

                My AJAX code:

                $.post('http://mysite.com/?q=menu_example/my_page', 
                    {'ycoord[]': ycoord, 'xcoord[]': xcoord }
                );
                

                Drupal PHP:

                Drupal PHP:

                $items['menu_example/my_page/%/%'] = array(
                    'title' => 'My Page', 
                    'description' => 'i hope this works', 
                    'page callback' => '_graphael', 
                    'page arguments' => array(2, 3), // fill this, 
                    'access callback' => true,
                    'type' => MENU_CALLBACK,
                );
                

                在我的控制台中,我看到 xcoordycoord 的值正在正确传输,但回调并不完全正常.我的问题:如何将数组传递给菜单回调?我还应该在 $items 键中使用 % 占位符吗?

                In my console, I see that the values for xcoord and ycoord are being properly transmitted, but the callback isn't quite working. My question: how would I pass arrays to a menu callback? Should I still use a % placeholder in the $items key ?

                推荐答案

                您传递给 $.post() 的第二个参数未附加到您作为第一个参数传递的 URL;它是在 $_POST 中传递给 PHP 的数据.

                The second argument you pass to $.post() is not attached to the URL you pass as first argument; it is data that is passed to PHP in $_POST.

                菜单回调的正确定义应如下所示.

                The correct definition for the menu callback should be the following one.

                $items['menu_example/my_page'] = array(
                  'title' => 'My Page', 
                  'description' => 'I hope this works', 
                  'page callback' => '_graphael', 
                  'access callback' => TRUE,
                  'type' => MENU_CALLBACK,
                );
                

                您的页面回调应该会在 $_POST 中找到从 jQuery 传递的数据.

                Your page callback should then find the data passed from jQuery in $_POST.

                这篇关于如何将数组传递给 Drupal 菜单回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Drupal 7 中用户的图片存储在哪里? 下一篇:解决 PHP 中不安全的随机数生成问题

                相关文章

                <small id='EwN8q'></small><noframes id='EwN8q'>

                • <bdo id='EwN8q'></bdo><ul id='EwN8q'></ul>
                  <legend id='EwN8q'><style id='EwN8q'><dir id='EwN8q'><q id='EwN8q'></q></dir></style></legend>
                  <tfoot id='EwN8q'></tfoot>

                    <i id='EwN8q'><tr id='EwN8q'><dt id='EwN8q'><q id='EwN8q'><span id='EwN8q'><b id='EwN8q'><form id='EwN8q'><ins id='EwN8q'></ins><ul id='EwN8q'></ul><sub id='EwN8q'></sub></form><legend id='EwN8q'></legend><bdo id='EwN8q'><pre id='EwN8q'><center id='EwN8q'></center></pre></bdo></b><th id='EwN8q'></th></span></q></dt></tr></i><div id='EwN8q'><tfoot id='EwN8q'></tfoot><dl id='EwN8q'><fieldset id='EwN8q'></fieldset></dl></div>