1

Created a new module to receive form values and process API in Craft CMS 4. How to make an AJAX request to access a controller in my module?

  • module name - giftcard
  • controller - GiftCardController
  • action - processRequest

Can someone help me on this context ?

1 Answer 1

3

The documentation on controllers has everything you need. An action path consists of the module ID, the name of the controller and the name of the action. In your case, the action path will be something like giftcard/gift-card/process-request. You can use that as the action parameter in a POST request, or you can POST directly to the action's URL (/actions/giftcard/gift-card/process-request, where the first segment depends on your actionTrigger setting).

You can make an AJAX request to that URL using fetch() or an HTTP library like axios.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.