1、drupal ajax json 异步调用模块文件结构: sitemode.info sitemode.module test_ajax.jssitemode.info; $Id$name = Sitemoddescription = A content type for jokes.package = Pro Drupal Developmentcore = 6.xsitemode.modulesitemod_callback_ajax,access arguments = array(access content),type = MENU_CALLBACK,);$itemstest/aja
2、x = array(/调用 form效果 见下图page callback = drupal_get_form,page arguments = array(get_ajax_form),/ 得到定义好的表单access arguments = array(access content),type = MENU_CALLBACK,);return $items;function get_ajax_form()/返回 form选选项drupal_add_js(drupal_get_path(module, sitemod) . /test_ajax.js);/加载 js文件$formnote_b
3、ook = array(#type = radios,#title = t(选择分类),#default_value = IBM,#options = array(t(IBM), t(Dell), t(Sony),t(HP),#description = t(选择你喜欢的品牌),);return $form;function sitemod_callback_ajax() $id = $_POSTid; /ajax post数据switch($id)case 0:drupal_json(array(html = drupal_get_form(ibm_form);/josn数据。formexi
4、t;break;case 1:drupal_json(array( html = drupal_get_form(dell_form);exit;break;function ibm_form()/定义表单$formibm = array(#type = checkboxes, #title = t(IBM最新型号电脑), #default_value = array(T410),#options = array(T400 = t(T400), T410 = t(T410), X200 = t(X200),X201 = t(X201),T410S = t(T410S),),#descripti
5、on = t(选择你喜欢的 IBM型号),);$formsubmit = array(#type = submit,#value = t(保存选择的信息),#weight = 40,);$form_stateredirect = test/view;return $form;function dell_form()/定义表单$formdell = array(#type = checkboxes, #title = t(Dell电脑), #default_value = array(d1),#options = array(d1 = t(d1), d2 = t(d2), d3 = t(d3),
6、),#description = t(选择你喜欢的 dELL型号),);$formsubmit = array(#type = submit,#value = t(保存选择的信息),#weight = 40,);return $form;/返回表单test_ajax.jsif(Drupal.jsEnabled) $(document).ready(function () $(input:radioname=note_book).click(function () var getSubmit = function(data) $(#footer).html(data.html);$.ajax(type: POST,url: /drupal/ajax,dataType: json,success: function(msg)/alert( msg);$(“#main“).prepend(msg.html);,data: id: $(input:radioname=note_book:checked).val(),);););