Skip to content

Latest commit

 

History

History
19 lines (13 loc) · 1 KB

File metadata and controls

19 lines (13 loc) · 1 KB

Making requests from JavaScript to modules

The External Module Framework provides the ajax() method on the Javascript Module Object (see documentation), which can be used to make server requests to the module. The module must process the request in the redcap_module_ajax hook and (optionally) return a response (see documentation).

module.ajax('action', payload).then(function(response) {
   // Process response
}).catch(function(err) {
   // Handle error
});

Actions must be declared in config.json, separately for authenticated (a user is logged in) and non-authenticated (surveys and other contexts where no user is logged in) contexts.

"auth-ajax-actions": [ "action1", "action2" ],

"no-auth-ajax-actions": [ "action2" ],

Note that for performance reasons and due to concurrency issues, the framework queues all requests and handles them sequentially in the order they are issued.