Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am in the process of converting Drupal 6 module to Drupal 7.
i have a problem of Passing php data to Ajax.
The function should display if a speaker on or off by interchanging icons, when clicked by using (toggle function).
whats i have discovered is that this part $.ajax() doesnt work, while in Drupal 6 it works.
below is the code.

longa.module file:

  //hook menu
  function longa_menu(){
  $items['longa/set_speaker_state'] = array(
   'page callback' => 'longa_set_speaker_state',
   'access arguments' => array('longa talk'),
   'type' => MENU_CALLBACK,
  return $items;
 //the callback
 function longa_set_speaker_state($speaker_state) {
  global $user;
  $_SESSION['longa_speaker_state'] = $speaker_state;
  user_save($user, array('longa_speaker_state' => $speaker_state));

longa.js file:

  if (Drupal.settings.longa_module.has_audio ==1){    
  im_flash_player_listener.onInit = function(){
    this.position = 0;
  if ($('#im-console-speaker-icon-on').css('display') == 'none') {
    is_muted = 1;
  else {
    is_muted = 0;
  $('#im-console-speaker-icon-on').click(function() {
    is_muted = 1;
    //alert('You clicked the speaker');
  $('#im-console-speaker-icon-off').click(function() {
    is_muted = 0;


 function set_speaker_state($speaker_state) {
  if (Drupal.settings.longa_module.has_perms ==0) {
 var sendurl= url_prefix + 'longa/set_speaker_state/' + $speaker_state;
   type: 'GET',
   url: sendurl ,
   dataType: 'json',
   data: 'js=1'
   /**success: function(xhr) { 
    alert('sent successfully');
    error:function(xhr) { 
   alert('error occured');

I will appreciate for any help.

share|improve this question
up vote 1 down vote accepted

In function set_speaker_state() , the $ symbol doesn't recognized, you must put set_speaker_state() function into:

(function($, window, undefined){
 // here!
})(jQuery, window);
share|improve this answer
i did as u suggested, removed the jQuery wich i added.. its working. Thank you. – mrcniceguy Dec 8 '12 at 7:56

Finally i got it working...i just replaced $.ajax with jQuery.ajax and bum, everything works.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.