PudiPudi
PudiPudi

Reputation: 38

Drupal 7 hook_menu() throws a 404

I have tried to acces it through an ajax call and by simply going to it by url, It always give me a 404

i have flushed my caches multiple times and even tried to remove and re-add the module (as i have had the problem with other modules and read on other responses on the problem)

i also have looked it up on internet, but i can't seem to find any solution
(module name : TTK_rest)

.module:

function TTK_rest_menu() {  
    $items = array();
    $items['TTK_rest_api/TTK_task_progression'] = array(
        'page callback' => 'TTK_task_progression_view',
        'access arguments' => array('access content'),
        'access callback' => TRUE,
        'type' => MENU_CALLBACK,
    );

    return $items;
}

function TTK_task_progression_view(){

    return '{"pom":"pom"}';
}

and the ajax call to it:

$.ajax({                 
                url:'/TTK_rest_api/TTK_task_progression',                   
                data: {"getProgress": "true"},//, "event_id":settings['TTK_task_progression']['jsEvent_id']
                type: "POST",
                contentType: "JSON",
                success: function(data){
                    var $data = $(data);
                    console.log(data);




                },
                error: function(err){
                    console.log("neupe, try again");
                }
            });

Upvotes: 0

Views: 481

Answers (1)

PudiPudi
PudiPudi

Reputation: 38

finally found the solution (posted the question after multiple hours of searching, if i've known i would have find an answer this quick i wouldn't have asked it.. still going to leave it up with a response in case there is someone with the same problem

solution to the problem was that i had to have my function name had to have the module name prefix

note: i have an other module called 'TTK_task_progression', might be the origin of the problem i had

solution:

function TTK_rest_menu() {  
    $items = array();
    $items['TTK_rest_api/TTK_task_progression'] = array(
        'page callback' => 'TTK_rest_progression', // <- changed
        'access arguments' => array('access content'),
        'access callback' => TRUE,
        'type' => MENU_CALLBACK,
    );

    return $items;
}

function TTK_rest_progression(){ // <- changed

    return '{"pom":"pom"}';
}

Upvotes: 0

Related Questions