Answers.Body: <p>The <a href="https://craftcms.com/docs/4.x/extend/controllers.html" rel="nofollow noreferrer">documentation on controllers</a> 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 <code>giftcard/gift-card/process-request</code>. You can use that as the <code>action</code> parameter in a POST request, or you can POST directly to the action's URL (<code>/actions/giftcard/gift-card/process-request</code>, where the first segment depends on your <a href="https://craftcms.com/docs/4.x/config/general.html#actiontrigger" rel="nofollow noreferrer"><code>actionTrigger</code> setting</a>).</p>
  <p>You can make an AJAX request to that URL using <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch" rel="nofollow noreferrer"><code>fetch()</code></a> or an HTTP library like <a href="https://github.com/axios/axios" rel="nofollow noreferrer">axios</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-17T13:30:47.590Z
Answers.LastActivityDate: 2023-11-17T13:30:47.590Z
Answers.UserDisplayName: MoritzLost
Body: <p>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?</p>
  <ul>
  <li>module name - <code>giftcard</code></li>
  <li>controller - <code>GiftCardController</code></li>
  <li>action - <code>processRequest</code></li>
  </ul>
  <p>Can someone help me on this context ?</p>
  
Tags: <plugin-craftcommerce><modules><ajax>
Title: How to make AJAX request to controller inside module?
ThreadText: # How to make AJAX request to controller inside module?
  
  (Asked by: username_0 on 2023-11-17)
  
  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 ?
  
  **Tags:** plugin-craftcommerce, modules, ajax
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-11-17. Score: 3
  
  The [documentation on controllers](https://craftcms.com/docs/4.x/extend/controllers.html) 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](https://craftcms.com/docs/4.x/config/general.html#actiontrigger)).
  
  You can make an AJAX request to that URL using [`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) or an HTTP library like [axios](https://github.com/axios/axios).
  
  
  ---
  
  