国外设计欣赏网站 - DOOOOR.com

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,微信登陆

搜索

[Drupal教程] Drupal:表单使用#ahah增强ajax体验

[复制链接]
发表于 1-14-2012 00:24 | 显示全部楼层 |阅读模式

Drupal为我们提供了表单的专用方法#ahah,所以只是将js里的ajax调用代码换了一种形式,更方便。

步骤:

一、表单中定义#ahah属性

01$form['submit'] = array(
02  '#type' => 'submit',
03  '#value' => 'SEARCH',
04  '#attributes' => array('class'=>'class-search'),
05  '#ahah' => array(
06    'event' => 'click',//定义触发事件类型
07    'method' => 'replace',//替换wrapper指向的容器里的内容,可以改成其它方式
08    'path' => 'class_search_results',//ahah调用的菜单路径
09    'wrapper' =>'content',//返回的内容将以method定义的方式来改变指定容器内容
10    'effect' => 'fade',//以渐现形式来显示返回的内容
11    'progress'=>array(
12      'type' => 'throbber',//会显示drupal默认的小时钟图标以表明是正在异步获取数据
13    ),
14  ),
15);

二、定义一个#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,
6);

三、定义调用路径的回调函数

1function class_search_results() {
2  $output 'hello, ahah!';
3  drupal_json(array('status' => TRUE, 'data' => $output));
4}

 


型动视觉摘自似水流云的博客,谢谢!





|2011-2026-版权声明|平台(网站)公约|DOOOOR 设计网 ( 吉ICP备2022003869号 )

GMT+8, 2-19-2025 13:46 , Processed in 0.540932 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表