<p>The "Craft" javascript global object can only be used in the backend, not on the frontend.</p>

CC BY-SA 3.0
2014-10-10T13:14:42.533Z
2014-10-10T13:14:42.533Z
naboovalley
<p>I have this function within my <code>&lt;script&gt;</code> tags:</p>

<pre><code>$('.btn').click(function()
{
    var data = {
        title: "This is a title"
    };

    Craft.postActionRequest('plugin/controller/action', data, function(response) {
    });
});
</code></pre>

<p>The "Craft" function returns as "TypeError: Craft is undefined". I'm guessing I somehow need to reference the scope to the function but I can't seem to get it to work.</p>

<p>I tried adding <code>_self = this</code> outside my jquery click function and reference Craft like "_self.Craft" but that didn't do it.</p>

<p>What am I missing here?</p>

CC BY-SA 3.0
2014-10-10T13:07:29.730Z
Is this front-end or back-end?
Andris Sevcenko
CC BY-SA 3.0
2014-10-10T13:12:47.613Z
It's for front-end use
naboovalley
CC BY-SA 3.0
2014-10-10T13:13:18.430Z
Oh man I'm so retarded... ofc I can't use it on the front-end. Haha... Mystery solved.
naboovalley
<plugin-development><javascript><jquery>
How reference "Craft" js object in jquery scope
# How reference "Craft" js object in jquery scope

(Asked by: username_0 on 2014-10-10)

I have this function within my

**Tags:** plugin-development, javascript, jquery
> **Comments:**
> **username_1**: Is this front-end or back-end?  
> **username_0**: It's for front-end use  
> **username_0**: Oh man I'm so retarded... ofc I can't use it on the front-end. Haha... Mystery solved.  

---

## 1 answers

### Answer by username_0 on 2014-10-10. Score: 3 | Accepted answer

The "Craft" javascript global object can only be used in the backend, not on the frontend.


---

