3

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

我的 AJAX 代码:

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

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,
);

在我的控制台中,我看到 和 的值xcoord正在ycoord正确传输,但回调并不能正常工作。我的问题:如何将数组传递给菜单回调?我还应该在密钥中使用%占位符吗?$items

4

1 回答 1

3

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

菜单回调的正确定义应该如下。

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

然后,您的页面回调应该会在$_POST.

于 2012-06-21T05:48:31.713 回答