Answers.Body: <p>The URL you call using Ajax shouldn't include the <code>action</code> trigger, since Craft will add this to call the correct method in your controller when it interprets the URL.</p>
  
  <p>So in the example you gave, your Ajax URL should be: <code>/actions/businessLogic/exampleAjax</code></p>
  
  <p>More details can be found in the <a href="https://craftcms.com/docs/plugins/controllers" rel="nofollow noreferrer">Plugin Development docs</a>.</p>
  
  <p>Note that if you change the <code>actionTrigger</code> in the <code>general.php</code> config file, then you will need to change the first segment of the Ajax URL to match the new value for the <code>actionTrigger</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-04T11:34:33.253Z
Answers.Text: Yeah, thank you. I didn't pay attention to to the 'action' prefix.
Answers.UserDisplayName: Alessio Breviglieri
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-04T10:57:43.860Z
Answers.LastActivityDate: 2017-09-04T10:57:43.860Z
Answers.UserDisplayName: Steve Rowling
Body: <p>I've a trigger on my frontend that requires an action. I've started from the businessLogic template but I'm getting a 404 and can't find why.</p>
  
  <p>My function</p>
  
  <pre><code>public function actionExampleAjax()
      {
        // Stuff
      }
  </code></pre>
  
  <p>How I call it</p>
  
  <pre><code>$.post('/actions/businessLogic/actionExampleAjax', data, function(response, textStatus, jqXHR) {
      // Stuff
  });
  </code></pre>
  
  <p>The server response ( 404):</p>
  
  <pre><code>The system is unable to find the requested action "actionExampleAjax".
  </code></pre>
  
  <p>The action trigger is set to:</p>
  
  <pre><code>'actionTrigger' =&gt; 'actions'
  </code></pre>
  
  <p>The same approach works fine with a form submission, but I don't want to use a form in this case.</p>
  
  <p>Any suggestion?</p>
  
Tags: <ajax><controller><404>
Title: Ajax call to action 404
ThreadText: # Ajax call to action 404
  
  (Asked by: username_0 on 2017-09-04)
  
  I've a trigger on my frontend that requires an action. I've started from the businessLogic template but I'm getting a 404 and can't find why.
  
  My function
  
  ```
  public function actionExampleAjax()
      {
        // Stuff
      }
  
  ```
  
  How I call it
  
  ```
  $.post('/actions/businessLogic/actionExampleAjax', data, function(response, textStatus, jqXHR) {
      // Stuff
  });
  
  ```
  
  The server response ( 404):
  
  ```
  The system is unable to find the requested action "actionExampleAjax".
  
  ```
  
  The action trigger is set to:
  
  ```
  'actionTrigger' => 'actions'
  
  ```
  
  The same approach works fine with a form submission, but I don't want to use a form in this case.
  
  Any suggestion?
  
  **Tags:** ajax, controller, 404
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-09-04. Score: 2 | Accepted answer
  
  The URL you call using Ajax shouldn't include the `action` trigger, since Craft will add this to call the correct method in your controller when it interprets the URL.
  
  So in the example you gave, your Ajax URL should be: `/actions/businessLogic/exampleAjax`
  
  More details can be found in the [Plugin Development docs](https://craftcms.com/docs/plugins/controllers).
  
  Note that if you change the `actionTrigger` in the `general.php` config file, then you will need to change the first segment of the Ajax URL to match the new value for the `actionTrigger`.
  
  > **Comments:**
  > **username_0**: Yeah, thank you. I didn't pay attention to to the 'action' prefix.  
  
  ---
  
  