Drupal 7 hook_menu with type MENU_CALLBACK gives 403 error

272 views Asked by At

I'm trying to implement a json endpoint via hook_menu. Here is my code:

function gcm_subscribe_menu() {
    $items['gcm_subscribe/subscribe'] = array(
        'title' => 'Test-Endpoint',
        'page_callback' => 'gcm_subscribe_ajax_subscribe',
        'type' => MENU_CALLBACK,
        'access arguments' => array('access content'),
    );

    return $items;
}

function gcm_subscribe_ajax_subscribe() {
    drupal_json(array('test' => 'testData'));
}

My problem is, that when i call this endpoint via javascript, i get an error 403.

Does someone know why?

1

There are 1 answers

0
B31 On

page callback is without the underscore, and in the callback function you should use return.

also, in d7 you shoud use drupal_json_output, instead drupal_json