I create the callback url 'swish_payment/request' in my hook_menu() function:

function swish_payments_menu(){
  $items['swish_payment/request'] = array(
    'type'             => MENU_CALLBACK,
    'page callback'    => '_ajax_payment_request',
    'access callback' => TRUE,
    'file' => 'src/controller/CallbackController.inc',
  return $items;

In the file CallbackController.inc, saved in the folder 'src/controller' stated after "file" above I have this:

function _ajax_payment_request() {

  drupal_json_output('It works!');


..just to check that the callback works. And this is how the js looks like in the client ('number' contains a string):

  dataType: "json",
  url : "swish_payment/request",
  cache: false,
  success: function (response) {

Under the networks tab i Chrome I can see that the url 'swish_payment/request' is found with a 200 code. But the console stays blank.

Can anyone give me a hint on what I am doing wrong?

EDITED: turns out that it worked when I moved the function from the external file into the .module file. Apparently it's a bad idea to split code into several files.

  • Just remove the line data:number, it will work
    – berramou
    Commented Sep 16, 2019 at 15:18
  • Hello. Thanks for your comment. See my edited question. The problem was that the function was not found in the separate file.
    – TBJ
    Commented Sep 16, 2019 at 15:29
  • I have tested your code as it is, it works so just check if your file located like YourModuleRoot/src/controller/CallbackController.inc
    – berramou
    Commented Sep 16, 2019 at 15:39
  • Thanks berramou. Well, I can't figure out why it does not work for me. The file is in the right place. For now, I will just continue with all code in the module file.
    – TBJ
    Commented Sep 17, 2019 at 6:37


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.