zoukankan      html  css  js  c++  java
  • [Drupal] My method of using ajax in Drupal

    That is just my method to create the ajax module. Here I will build a module "myajax" and locate it in sites/all/modules/


    1. Create the .info file, insert the content as below.

    ;$Id$
    name
    = My Ajax Module
    description
    = This is a module which is used when you can do with ajax in the server.
    core
    = 6.x
    version
    = "6.x-1.7"

    2. Create the .module file, inster the code as below.

    代码
    <?php
    /**
    * @file
    * My Ajax Module
    *
    * This is a module which is used when you can do with ajax in the server.
    *
    */
    function myajax_menu() {
    $items = array();

    $items['insertsth'] = array(
    'page callback'=>'myajax_insertsth',
    'access callback'=>TRUE,
    'type'=>MENU_CALLBACK,
    );
    return $items;

    }

    function myajax_insertsth () {
    //In this function, you can handle with the parameters sent from the client.

    //Use $_GET

    var_dump($_GET);

    //use $_POST
    var_dump($_POST);


    //REMEMBER that after you handing with the data, use the die() to stop to load the whole page.
    die();
    //echo "Hello, world!";die();
    }

    3. Test now!
    Now you can insert a test url, such as http://www.example.com/myajax/111, then you can see the result.
    Of course, you can create a form, and post the data to the url.


    If you have any good idea about how to use ajax in Drupal, please tell me!  :)

  • 相关阅读:
    linux常用命令(4)rm命令
    Apache Commons 工具类
    Apache Commons 工具类介绍及简单使用
    linux常用命令(3)mkdir命令
    linux常用命令(2)pwd命令
    linux常用命令(1)cd命令
    小程序调用方法
    php用json_encode中文问题
    基于thinkphp的RBAC权限控制
    thinkphp获取ip地址及位置信息
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/1799796.html
Copyright © 2011-2022 走看看