Inactive User
12 years agoJquery in endpoint
This might be a dumb question but I can't seem to use Lithium's jQuery in an endpoint. For instance, I'm trying to create a javascript file with some common js functions we're using in an endpoint bu...
Sorry, I should've given some more detail. I understand the entire stand-alone nature. I had set the type of endpoint to text/javascript and then included it in the wrapper footer using a script tag, since I thought the Lithium jQuery would have loaded by then. The JS loads fine but when it tries to use $, I come across the error.
Here's the watered down code:
(function($){ test = { url: "https://lithiumdev.domain.com/restapi/vc/search/messages", //used our real domain in the actual code getByLabel: function(labelName, callback){ var data = { q: "is_root:true AND labels:"+ labelName } $.post(test.url, data, callback); }, displayMessageInfo: function(data){ console.log(data); } } })(LITHIUM.jQuery);
I call the function test.getByLabel('test',test.displayMessageInfo) and then the error happens: TypeError: Cannot call method 'post' of undefined'.
I may be thinking about this all wrong or it may be something dumb. But, anyways, thanks for the help!
Not sure why that's not working. Have you checked that LIHTIUM.jQuery is defined when your code is executed (e.g. by debugging)?
You could also try referencing jQuery directly (via $.POST(...) outside the object) to check jQuery has been loaded.