title: How to return a JSON object instead of text/html in Drupal
body: <p>I am trying to pass an id for getting the output array in Ajax but I get the type as text/html so for that I got error as <em>404 not found</em>. I need to get text/json.</p>
  
  <p>PHP (Drupal):</p>
  
  <pre><code>function footfall_source()
  {
  
  $form['foodfall_source_submit'] = array(
    '#type' =&gt; 'button',
    '#size' =&gt; 15,
    '#id' =&gt; 'foodfall-submit',
    '#value' =&gt; 'Fetch',
    '#name' =&gt; 'foodfall_source_submit',
    '#attributes' =&gt; array('onclick' =&gt; 'foodfallList()'),
  );
  
  if (isset($_POST['id'])) {
      $userid = $_POST['id'];
      drupal_set_message($userid);
      $output = array('success' =&gt; 'false', 'message' =&gt; 'Ajax Failed');
  
      drupal_json_output($output);
      drupal_exit();
  }
  else {
      drupal_set_message('No POST');
  }  
  return $form;
  }
  </code></pre>
  
  <p>JavaScript with Ajax:</p>
  
  <pre><code>   $('#load').show();
      var foodfall_start_date = $('#foodfall-start-date').val();
      var foodfall_end_date = $('#foodfall-end-date').val();                    
                  var url = '/diner/footfallsource';                   
    $.ajax({ 
    type: 'POST', 
    dataType: 'html',
    url: url,  
    data : {id : '1'},
    success: function(data){
             alert(data);
    },
    error: function(data,tt, ee){
             alert(tt+" - "+ ee); // 404 Not Found
    }
  });
  </code></pre>
  
  <p>Thanks in advance.</p>