Drupal为我们提供了表单的专用方法#ahah,所以只是将js里的ajax调用代码换了一种形式,更方便。 步骤: 一、表单中定义#ahah属性 01 | $form [ 'submit' ] = array ( |
04 | '#attributes' => array ( 'class' => 'class-search' ), |
07 | 'method' => 'replace' , |
08 | 'path' => 'class_search_results' , |
09 | 'wrapper' => 'content' , |
二、定义一个#ahah要调用的路径 1 | $items [ 'class_search_results' ] = array ( |
2 | 'title' => t( 'Search Results' ), |
3 | 'page callback' => 'class_search_results' , |
4 | 'access callback' => TRUE, |
5 | 'type' => MENU_CALLBACK, |
三、定义调用路径的回调函数 1 | function class_search_results() { |
2 | $output = 'hello, ahah!' ; |
3 | drupal_json( array ( 'status' => TRUE, 'data' => $output )); |
型动视觉摘自似水流云的博客,谢谢!
|