Calling a module function name in Ajax URL I am developing a custom payment gateway for Drupal Commerce. I am getting some problems calling a custom module function from an AJAX URL.

How do I call a module function from a custom AJAX request?    

function custom_gateway_settings_form($settings) {
  $form = array();   

  $form['code'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Code'),
    '#maxlength' =&gt; 100,
    '#description' =&gt; t('Code.'),  
    '#prefix' =&gt; '&lt;div id="tabs-code" style = "display:none"&gt;',
    '#suffix' =&gt;'&lt;/div&gt;',
  );

  $form['btncode'] = array(
    '#type' =&gt; 'submit',
    '#id' =&gt; 'btncode',
    '#value' =&gt; 'Get the code',
  );
}


The JavaScript code is the following one.

   jQuery("#btncode").click(function() { 
     jQuery.ajax({
       type: "POST", 
       url: Drupal.settings.basePath + "/?p=ajaxGetCode",
       cache: false,
       beforeSend: function() {
         // jQuery('.loadrimage').show();
         // jQuery(".error").hide();
       },
       complete: function() {
         // jQuery('.loadrimage').hide();
       },   
       success: function(htmlText) {
         alert(htmlText);
       }
   });
You have to create own endpoint and call post on it. For example create menu element using hook_menu:

$items['my-module-ajax-endpoint'] = array(
   'page callback' =&gt; 'my_module_ajax_callback', 
   'delivery callback' =&gt; 'ajax_deliver', 
   'access arguments' =&gt; array('access content'), 
   'type' =&gt; MENU_CALLBACK,
);


And now post to it.