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):
$.ajax({
data:number,
dataType: "json",
type:"POST",
url : "swish_payment/request",
cache: false,
success: function (response) {
console.log(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.
data:number,
it will workYourModuleRoot/src/controller/CallbackController.inc