• [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!  :)

  • 相关阅读:
    验证码处理函数
    Apache2.2下载及安装
    centos6.4、6.5、7.0环境下载及安装
    数据库实务 实务隔离级别
    InnoDB 锁
    索引常见问题处理
    数据库索引 B-Tree索引 hash索引
    JVM学习-(2)
    jvm学习-(1)
    linux杂记
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/1799796.html
Copyright © 2020-2023  润新知