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

  • 相关阅读:
    Binary Tree Maximum Path Sum
    ZigZag Conversion
    Longest Common Prefix
    Reverse Linked List II
    Populating Next Right Pointers in Each Node
    Populating Next Right Pointers in Each Node II
    Rotate List
    Path Sum II
    [Leetcode]-- Gray Code
    Subsets II
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/1799796.html
Copyright © 2011-2022 走看看