<p>From <a href="https://craftcms.com/docs/3.x/extend/controllers.html#requesting-your-controller-action" rel="nofollow noreferrer">Craft CMS documentation page</a> about requesting controller action:</p>
<p>when you send action as parameter, format should be without '/actions':</p>
<pre><code> &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;plugin-handle/controller/action&quot;&gt;
</code></pre>
<p>and you can directly open that URL directly- with 'actions' at the beginning as default actionTrigger - because:</p>
<blockquote>
<p>By default, Craft makes an actions/ route available for appending any
valid action path.</p>
</blockquote>
<p>so <code>http://craftsite/actions/plugin-handle/controller/action</code> can be resolved when open that URL in a browser.</p>

CC BY-SA 4.0
2021-09-22T21:42:53.633Z
2021-09-22T22:08:43.150Z
2021-09-22T22:08:43.150Z
user9975
<p>I'm able to call my controller action directly from a url in the browser and get the proper response but when I call it from a page with js I get a 404 error. I'm working off the solution found here <a href="https://craftcms.stackexchange.com/questions/11867/call-plugin-controller-from-frontend-with-ajax">Call plugin controller from frontend with ajax</a> but I receive the same issue.</p>
<p>My current code looks like:</p>
<pre><code>&lt;form id=&quot;call-support-form&quot; action=&quot;&quot; class=&quot;form&quot; method=&quot;post&quot; accept-charset=&quot;UTF-8&quot;&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;actions/sage-dashboards-module/sagedashboards/do-something&quot;&gt;
            &lt;input class=&quot;button&quot; type=&quot;submit&quot; value=&quot;Support adhérents&quot;&gt;
&lt;/form&gt;

    $(&quot;#call-support-form&quot;).submit( function(e) {

e.preventDefault();

var data = $(this).serialize();

$.ajax({
    method: 'POST',
    url: '/',
    data: data,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    success: function (response) {
            //  ...
        },
        error: function (XMLHttpRequest, textStatus) {
            console.log(XMLHttpRequest)
            console.log(&quot;Status: &quot; + textStatus);
        }
})

});
</code></pre>
<p>Any ideas on what I've done incorrectly? I've gotten this working on previous projects using CraftCMS but for some reason nothing I try currently is changing anything.</p>

<controller><javascript><post>
404 Error Controller Action From Jquery But Not Url
# 404 Error Controller Action From Jquery But Not Url

(Asked by: username_0 on 2021-09-22)

I'm able to call my controller action directly from a url in the browser and get the proper response but when I call it from a page with js I get a 404 error. I'm working off the solution found here Call plugin controller from frontend with ajax but I receive the same issue.
My current code looks like:

            
            


    $("#call-support-form").submit( function(e) {

e.preventDefault();

var data = $(this).serialize();

$.ajax({
    method: 'POST',
    url: '/',
    data: data,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    success: function (response) {
            //  ...
        },
        error: function (XMLHttpRequest, textStatus) {
            console.log(XMLHttpRequest)
            console.log("Status: " + textStatus);
        }
})

});

Any ideas on what I've done incorrectly? I've gotten this working on previous projects using CraftCMS but for some reason nothing I try currently is changing anything.

**Tags:** controller, javascript, post


---

## 1 answers

### Answer by username_1 on 2021-09-22. Score: 2 | Accepted answer

From Craft CMS documentation page about requesting controller action:
when you send action as parameter, format should be without '/actions':
 

and you can directly open that URL directly- with 'actions' at the beginning as default actionTrigger - because:

By default, Craft makes an actions/ route available for appending any
valid action path.

so http://craftsite/actions/plugin-handle/controller/action can be resolved when open that URL in a browser.


---

