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

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

在我的控制台中,我看到xcoordycoord的值被正确传输,但回调函数却不起作用。我的问题是:如何将数组传递给菜单回调函数?我是否仍应在$items键中使用%占位符?
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中找到从jQuery传递的数据。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接