How to call function from PHP file (or another module) in JS file from my custom module?
You can add a menu callback in your module, that will be used by JS to send-receive values from PHP.

/**
 * Implements hook_menu().
 */
function my_module_menu() {
  $items = array();
  $items['my-module/my-function'] = array(
    'title' =&gt; 'Ajax callback for my function.',
    'page callback' =&gt; 'my_module_function',
    'access arguments' =&gt; array('access content'),
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}

function my_module_function() {
  // Remember you have to print your results if you want to
  // send any values back to JS.
  print 'Hi, there!';
  drupal_exit();
}


Now in your JS code, you make an Ajax call and, optionally, get values back from PHP (if desired).

$.ajax({
  url: Drupal.settings.basePath + "?q=my-module/my-function",
  done: function(data) {
    // If my_module_function returns any value, it will come in the data variable.
    alert(data);
  }
});