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...
When you're testing the endpoint, are you accessing it directly, or are you including it as an external JavaScript file in one of the community pages, or something else perhaps? The important thing to keep in mind about endpoints is that they're entirely stand-alone. None of the core CSS, JS, HTML, etc. is included with endpoints.
So to properly test your endpoint, you'd likely have to include it in one of the community pages and ensure that it's loaded after the core Lithium libraries have loaded (to ensure that the LITHIUM.jQuery object is available at the time you're trying to access it).
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!