<p>You're definitely on the right track, just missing out on a couple of key details!</p>

<p>The <code>actionUrl</code> function generates a normal, full URL... <em>it's not (by default) an AJAX call</em>. So your browser is actually navigating away from the previous page, and pinging your controller as a completely separate HTTP request.</p>

<p>Which leads to the next detail... Unless you're pinging your controller via AJAX, you need to then have your controller tell the request where to go. Don't forget, <strong>the request will continue on</strong>, even after your controller has worked its magic.</p>

<blockquote>
  <p><a href="http://buildwithcraft.com/docs/plugins/controllers#how-controller-actions-fit-into-routing">... if the controller doesn’t call a response function, Craft will continue on with its request routing...</a></p>
</blockquote>

<p>So you'll usually want to make sure your controller ends with a directive on what to do next. The most common options are:</p>

<ul>
<li>Render a template</li>
<li>Redirect to a new page</li>
<li>Return a JSON response (if you called it via AJAX)</li>
</ul>

<p>The list of options to render/redirect/return are mixed in with the other <a href="http://buildwithcraft.com/docs/plugins/controllers#baseController-methods">BaseController Methods in the documentation...</a></p>

CC BY-SA 3.0
2016-09-26T02:07:29.790Z
Ah! I missed that key piece of info too. Thanks.
JamesNZ
CC BY-SA 3.0
2014-12-25T17:34:19.057Z
2014-12-25T17:34:19.057Z
Lindsey D
<p>I'm writing my first plugin and I'm slowly getting there, but I hit on a problem:</p>

<p>I have a controller class in which I have a function that sets a cookie.
I call on this function from within a template with <code>actionUrl()</code>.</p>

<p>The weird thing is, the cookie is being set (so the controller action is found and executed) but I still get a 404 page on the action path.</p>

<p>Anybody has an idea what could be wrong?</p>

<controller><404-page>
Controller action works but still gives 404
# Controller action works but still gives 404

(Asked by: username_0 on 2014-12-25)

I'm writing my first plugin and I'm slowly getting there, but I hit on a problem:

I have a controller class in which I have a function that sets a cookie.
I call on this function from within a template with `actionUrl()`.

The weird thing is, the cookie is being set (so the controller action is found and executed) but I still get a 404 page on the action path.

Anybody has an idea what could be wrong?

**Tags:** controller, 404-page


---

## 1 answers

### Answer by username_1 on 2014-12-25. Score: 8 | Accepted answer

You're definitely on the right track, just missing out on a couple of key details!

The `actionUrl` function generates a normal, full URL... *it's not (by default) an AJAX call*. So your browser is actually navigating away from the previous page, and pinging your controller as a completely separate HTTP request.

Which leads to the next detail... Unless you're pinging your controller via AJAX, you need to then have your controller tell the request where to go. Don't forget, **the request will continue on**, even after your controller has worked its magic.

> [... if the controller doesn’t call a response function, Craft will continue on with its request routing...](http://buildwithcraft.com/docs/plugins/controllers#how-controller-actions-fit-into-routing)

So you'll usually want to make sure your controller ends with a directive on what to do next. The most common options are:

* Render a template
* Redirect to a new page
* Return a JSON response (if you called it via AJAX)

The list of options to render/redirect/return are mixed in with the other [BaseController Methods in the documentation...](http://buildwithcraft.com/docs/plugins/controllers#baseController-methods)

> **Comments:**
> **username_2**: Ah! I missed that key piece of info too. Thanks.  

---

