1

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?

2

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.

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.

|improve this answer|||||
  • Yeah, thank you. I didn't pay attention to to the 'action' prefix. – Alessio Breviglieri Sep 4 '17 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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