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

  • 相关阅读:
    2010上交:计算表达式
    添加子评论
    上传图片
    settings配置 文件操作
    django 操作前端数据
    静态文件配置
    render httprequest
    上传文件配置
    Django为什么要跳转到不同的页面来实现不同的功能
    定义日志器
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/1799796.html
Copyright © 2011-2022 走看看