[development] how to right AJAX enabled module?

Amr Mostafa amr.mostafa at gmail.com
Sun Jul 15 11:28:28 UTC 2007

Hello Ahmed,

In Drupal5 I do this by creating a menu item of the type
MENU_CALLBACK, with a callback e.g. mymodule_get_rank_json() which
goes like:

function mymodule_get_rank_json() {
  // ...
  // The code to determine rank and put it in $rank.
  // ...

  // This is how to JSON-ify the returned value
  header('Content-type: text/javascript');
  print drupal_to_js($rank);

drupal_to_js() converts the given parameter to JSON and then you print
that back to the browser. To capture the returned information using
javascript and do something useful with it, check Ajax documentation
in jQuery library (the library that is included and used by default
within Drupal) http://docs.jquery.com/Ajax

- Amr

On 7/15/07, Ahmad Al-Obaidy <ahmad at hitech-iraq.com> wrote:
> Hi,
> I need to display a value given in the database.... the value is modified
> regularly by other programs....
> the value should be refreshed regularly .... but not the entire page...
> I tried JSON ... but didnt find a useful docs..
> from where should i start?

More information about the development mailing list