Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I would like to pass data from Javascript to PHP using Drupal 7.14. To this end, I'm trying to follow this SO post: http://stackoverflow.com/questions/4834132/how-to-pass-jquery-variable-to-drupal-ajaxhttps://stackoverflow.com/questions/4834132/how-to-pass-jquery-variable-to-drupal-ajax.

However, |hook_menu()` is not working as expected.

function example_module_menu() {
  $items = array();

  $items['example_callback/%'] = array(
    'title' => 'My Custom Callback', 
    'description' => 'Description', 
    'page callback' => 'my_custom_php_function', 
    'page arguments' => array(1), // fill this
    // 'access arguments' => array('access content'), 
    'access callback' => true,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Function that gets called from JQuery asynchronously. 
 */
function my_custom_php_function($argument) {
  // Do something with $argument...
  echo $argument;   
}

In my understanding, going to http://mywebsite.com/example_callback should call my_custom_php_function. Instead, I get:

The requested URL /example_callback was not found on this server.

Are there other steps necessary to write a simple menu callback?

I would like to pass data from Javascript to PHP using Drupal 7.14. To this end, I'm trying to follow this SO post: http://stackoverflow.com/questions/4834132/how-to-pass-jquery-variable-to-drupal-ajax.

However, |hook_menu()` is not working as expected.

function example_module_menu() {
  $items = array();

  $items['example_callback/%'] = array(
    'title' => 'My Custom Callback', 
    'description' => 'Description', 
    'page callback' => 'my_custom_php_function', 
    'page arguments' => array(1), // fill this
    // 'access arguments' => array('access content'), 
    'access callback' => true,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Function that gets called from JQuery asynchronously. 
 */
function my_custom_php_function($argument) {
  // Do something with $argument...
  echo $argument;   
}

In my understanding, going to http://mywebsite.com/example_callback should call my_custom_php_function. Instead, I get:

The requested URL /example_callback was not found on this server.

Are there other steps necessary to write a simple menu callback?

I would like to pass data from Javascript to PHP using Drupal 7.14. To this end, I'm trying to follow this SO post: https://stackoverflow.com/questions/4834132/how-to-pass-jquery-variable-to-drupal-ajax.

However, |hook_menu()` is not working as expected.

function example_module_menu() {
  $items = array();

  $items['example_callback/%'] = array(
    'title' => 'My Custom Callback', 
    'description' => 'Description', 
    'page callback' => 'my_custom_php_function', 
    'page arguments' => array(1), // fill this
    // 'access arguments' => array('access content'), 
    'access callback' => true,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Function that gets called from JQuery asynchronously. 
 */
function my_custom_php_function($argument) {
  // Do something with $argument...
  echo $argument;   
}

In my understanding, going to http://mywebsite.com/example_callback should call my_custom_php_function. Instead, I get:

The requested URL /example_callback was not found on this server.

Are there other steps necessary to write a simple menu callback?

added 51 characters in body
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

I would like to pass data from Javascript to PHP using Drupal 7.14. To this end, I'm trying to follow this SO post: http://stackoverflow.com/questions/4834132/how-to-pass-jquery-variable-to-drupal-ajax.

However, hook_menu|hook_menu()` is not working as expected.

function example_module_menu() {
  $items = array();

  $items['example_callback/%'] = array(
    'title' => 'My Custom Callback', 
    'description' => 'Description', 
    'page callback' => 'my_custom_php_function', 
    'page arguments' => array(1), // fill this
    // 'access arguments' => array('access content'), 
    'access callback' => true,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Function that gets called from JQuery asynchronously. 
 */
function my_custom_php_function($argument) {
  // Do something with $argument...
  echo $argument;   
}

In my understanding, going to http://mywebsite.com/example_callback should call my_custom_php_function. Instead, I get  : The requested URL /example_callback was not found on this server.

The requested URL /example_callback was not found on this server.

Are there other steps necessary to write a simple menu callback?

I would like to pass data from Javascript to PHP using Drupal 7.14. To this end, I'm trying to follow this SO post: http://stackoverflow.com/questions/4834132/how-to-pass-jquery-variable-to-drupal-ajax.

However, hook_menu is not working as expected.

function example_module_menu() {
$items = array();

$items['example_callback/%'] = array(
'title' => 'My Custom Callback', 
'description' => 'Description', 
'page callback' => 'my_custom_php_function', 
'page arguments' => array(1), // fill this
//'access arguments' => array('access content'), 
'access callback' => true,
'type' => MENU_CALLBACK,
 );

 return $items;
}

/**
* Function that gets called from JQuery asynchronously. 
*/
function my_custom_php_function($argument) {
 // Do something with $argument...
echo $argument; 
}

In my understanding, going to http://mywebsite.com/example_callback should call my_custom_php_function. Instead, I get  : The requested URL /example_callback was not found on this server.

Are there other steps necessary to write a simple menu callback?

I would like to pass data from Javascript to PHP using Drupal 7.14. To this end, I'm trying to follow this SO post: http://stackoverflow.com/questions/4834132/how-to-pass-jquery-variable-to-drupal-ajax.

However, |hook_menu()` is not working as expected.

function example_module_menu() {
  $items = array();

  $items['example_callback/%'] = array(
    'title' => 'My Custom Callback', 
    'description' => 'Description', 
    'page callback' => 'my_custom_php_function', 
    'page arguments' => array(1), // fill this
    // 'access arguments' => array('access content'), 
    'access callback' => true,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Function that gets called from JQuery asynchronously. 
 */
function my_custom_php_function($argument) {
  // Do something with $argument...
  echo $argument;   
}

In my understanding, going to http://mywebsite.com/example_callback should call my_custom_php_function. Instead, I get:

The requested URL /example_callback was not found on this server.

Are there other steps necessary to write a simple menu callback?

Post Migrated Here from stackoverflow.com (revisions)
Source Link
Blaine
  • 123
  • 8

Simple Drupal hook_menu

I would like to pass data from Javascript to PHP using Drupal 7.14. To this end, I'm trying to follow this SO post: http://stackoverflow.com/questions/4834132/how-to-pass-jquery-variable-to-drupal-ajax.

However, hook_menu is not working as expected.

function example_module_menu() {
$items = array();

$items['example_callback/%'] = array(
'title' => 'My Custom Callback', 
'description' => 'Description', 
'page callback' => 'my_custom_php_function', 
'page arguments' => array(1), // fill this
//'access arguments' => array('access content'), 
'access callback' => true,
'type' => MENU_CALLBACK,
 );

 return $items;
}

/**
* Function that gets called from JQuery asynchronously. 
*/
function my_custom_php_function($argument) {
 // Do something with $argument...
echo $argument; 
}

In my understanding, going to http://mywebsite.com/example_callback should call my_custom_php_function. Instead, I get : The requested URL /example_callback was not found on this server.

Are there other steps necessary to write a simple menu callback?