Ajax Function jquery Fails to send data Drupal 7 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=array();
  $items['longa/set_speaker_state'] = array(
   'page callback' =&gt; 'longa_set_speaker_state',
   'access arguments' =&gt; array('longa talk'),
   'type' =&gt; 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' =&gt; $speaker_state));
 }


longa.js file:

(function($){
 $(document).ready(function(){
  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() {
    set_speaker_state(1);
    is_muted = 1;
    //alert('You clicked the speaker');
    $('#im-console-speaker-icon-on').toggle();
    $('#im-console-speaker-icon-off').toggle();
    });
  $('#im-console-speaker-icon-off').click(function() {
    set_speaker_state(1);
    is_muted = 0;
    $('#im-console-speaker-icon-on').toggle();
    $('#im-console-speaker-icon-off').toggle();
    });
  }

 });
})(jQuery);

 function set_speaker_state($speaker_state) {
  if (Drupal.settings.longa_module.has_perms ==0) {
   return;
  }
 var sendurl= url_prefix + 'longa/set_speaker_state/' + $speaker_state;
  //alert(sendurl);
   $.ajax({
   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.
In function set_speaker_state() , the $ symbol doesn't recognized, you must put set_speaker_state() function into:

(function($, window, undefined){
 // here!
})(jQuery, window);