tags:

views:

25

answers:

1

Hello, I would like to ask can one create a page that outputs JSON data as a response to Jquery Ajax request?

In a non-drupal way, I would just create a php file, for example mypage.php and then I would use http://mysite.com/mypage.php?foo=bar as the URL for my AJAX request. This page will then output JSON data using json_encode().

How can I do it the Drupal way?

Thanks!

A: 

The JSON server module gives you JSON output of nodes. If you want more custom JSON, you can use hook_menu() to create a new menu callback (basically a URL path pointed to a function) and then use drupal_json() within that callback to send the output as JSON rather than the default HTML.

Scott Reynen