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.
$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 accesstargetUrilike that (it's not a variable)...you'll need to usethis.targetUriormyApp.targetUri