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' => 'Handler',
'description' => 'handler for File Upload',
'page callback' => 'handler',
//'access arguments' => array('access my_module_name via ajax'),
'access arguments' => array('access example ajax'),
'type' => 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?
function handler(){ print_r($_POST); }
– H. S. Mar 20 '16 at 9:50drupal_json_output($_POST); drupal_exit();
– Yogesh Mar 20 '16 at 9:54hook_menu
into<module_name>_menu
(perhaps post the whole menu hook too)? There are a lot of places where this might go wrong. – Neograph734 Mar 20 '16 at 10:37