0

I'm using the following as a namespace pattern:

var myApp = {

    targetUri: '/path/to/api',

    poll: function()
    {
        $.getJSON(targetUri, null, function(data)
        {
            // ...
        });
    }
};

However, I'm getting an error that $ is undefined on the getJSON line. I'm guessing that the $ object doesn't get scope inside the namespace. How can I resolve this?

I've tried using the = function() variant of the pattern (module pattern), but this is blocked by Content Security Policy (CSP) as part of unsafe-eval.

2
  • 5
    $ will be declared globally, so you shouldn't have trouble accessing it in any scope. If $ is undefined, that means you didn't include jQuery on your page (or the path to the file is wrong). In addition, you can't just access targetUri like that (it's not a variable)...you'll need to use this.targetUri or myApp.targetUri Commented Sep 8, 2014 at 14:24
  • Oh, wow, I feel like an idiot. I'd loaded the wrong damn header into my view, so it was missing the jQuery include. Thanks for pointing me in the right direction. Commented Sep 8, 2014 at 14:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.