Data not received on server in ajax I'm trying to post data from ajax to php page which I made in the hook_menu, called "handler".
So I have "domain.com/handler" which I try to do this in it:

function handler(){
  print_r($_POST);
}


and the hook looks like this:

$items['handler'] = array(
  'title' =&gt; 'Handler',
  'description' =&gt; 'handler for File Upload',        
  'page callback' =&gt; 'handler',
  //'access arguments' =&gt; array('access my_module_name via ajax'),
  'access arguments' =&gt; array('access example ajax'),
  'type' =&gt; MENU_CALLBACK
);


and on my js file i do this:

$.ajax({
  url: "/handler",
  type: "POST",
  dataType: "json",
  data: {"name":"John","location":"Boston"} 
})


and its wrapped inside Drupal.behaviors.mymodule = {...}
when I run the ajax, the response I get is an empty array.
why don't I receive the data?
$_POST is:


  An associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request.


That's not what you're doing. To receive JSON data in PHP you need to use:

$data = json_decode(file_get_contents('php://input'), true);
print_r($data);


Or change the data type of your AJAX request to one of the values that will result in $_POST being populated.