I recently took over an existing Drupal project and I tried to add a new PHP function (which works regularly) and link it with an Ajax query. There were already some in place that worked, and I wanted to add one that when you press a link, it sends the ID in the link to a PHP function which generates an info field. By copying the working code I got to this:
In my module, I added a menu
hook referring to the PHP function in the module and the Ajax link:
$items['api/feedback'] = array( 'page callback' => 'admin_user_feedback', 'access arguments' => array('access feedback'), 'access callback' => TRUE ); return $items;
This is my Ajax code:
function getFeedback(id){ $.ajax({ type: "POST", url: 'api/feedback', dataType: 'json', data: { 'id': id, }, success: function(data){ alert("success"); }, error: function(){ alert("error"); }, }); }
I know the function gets called on, but the console gives this error:
POST http://localhost:8080/site/api/feedback 404 (Not Found)
The URL is correct, the other APIs with similar URLs do work, so somehow he doesn’t recognise this API, I must have missed something. Does anybody know?