Answers.Body: <p>The "Craft" javascript global object can only be used in the backend, not on the frontend.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-10T13:14:42.533Z
Answers.LastActivityDate: 2014-10-10T13:14:42.533Z
Answers.UserDisplayName: naboovalley
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-10T13:07:29.730Z
Comments.Text: Is this front-end or back-end?
Comments.UserDisplayName: Andris Sevcenko
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-10T13:12:47.613Z
Comments.Text: It's for front-end use
Comments.UserDisplayName: naboovalley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-10T13:13:18.430Z
Comments.Text: Oh man I'm so retarded... ofc I can't use it on the front-end. Haha... Mystery solved.
Comments.UserDisplayName: naboovalley
Tags: <plugin-development><javascript><jquery>
Title: How reference "Craft" js object in jquery scope
ThreadText: # How reference "Craft" js object in jquery scope
  
  (Asked by: username_0 on 2014-10-10)
  
  I have this function within my `<script>` tags:
  
  ```
  $('.btn').click(function()
  {
      var data = {
          title: "This is a title"
      };
  
      Craft.postActionRequest('plugin/controller/action', data, function(response) {
      });
  });
  
  ```
  
  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.
  
  I tried adding `_self = this` outside my jquery click function and reference Craft like "\_self.Craft" but that didn't do it.
  
  What am I missing here?
  
  **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.
  
  
  ---
  
  