How to return JSON data using Drupal 7 card.module

drupal_add_js('jQuery(document).ready(function () {

  currentRequest = $.ajax({
  timeout:0,
  cache: false,
  url: pageUrl,
  dataType: "json",
  type: "GET",
  success: function(data){
  $("#edit-field-currency-type-und-0-value").val(data.currency);

  }

});


ajax request module

$items['mccurr/%'] = array(
'title' =&gt; '', 
'page callback' =&gt; 'ajax_currency_type', 
'access arguments' =&gt; array('access content'), 
'page arguments' =&gt; array(1),
'type' =&gt; MENU_SUGGESTED_ITEM,
);

function ajax_currency_type($ccode){
 drupal_add_http_header('Content-Type', 'application/javascript; utf-8');
$query = "SELECT countries_country.currency 
        FROM countries_country
        WHERE countries_country.iso2 = '".$ccode."'";
$data = db_query($query);

return drupal_json_encod($data);
}


Is this the correct way to return json data. If not, how should it be accomplished? I would like to return the data back to car.module.

Thank You
To return $data in json format using Drupal-7's page callback output, you should return through :

drupal_json_output($data);


in your page callback function.
For more ref : http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_json_output/7

Note : in your javascript in car.module, var pageUrl seems undefined. Make sure it is defined.