Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Querying from Javascript Use-API helper

Avatar

Level 5

I have a search component built in sightly that I want to use to query on a number of parameters associated to find news articles (which are simply cq:pages) in our content repository. I know how I would do this with the Java Use-API, but want to use the javascript api in this particular case (partly because I'm trying to learn how t he JS API works).

In a similar component built years ago, I used a jquery.ajax() call to /bin/querybuilder.json, however, I can't figure out how to include jquery successfully in my code (I can include the jquery dependency ok, but get an error when trying to call on the jQuery object). Additionally, I'm not sure if this is even the best thing to do--that perhaps some javascript implementation of the querybuilder is exposed through a generally available variable.

Any guidance is appreciated.

4 Replies

Avatar

Level 4
You cannot use JQuery inside JS Use API. That's server side javascript and you are very limited in what libraries you can use.

Avatar

Level 5

Ok, that makes sense. I'm trying to find more documentation on the JS USE-Api, if anyone can point me in the right direction, I'd appreciate it.

Ben

Avatar

Level 10

Its always recommended to use OSGi for querying and you can call this servlet using jquery.

refer this https://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

Avatar

Level 3

Hi All,

I am looking for a similar kind of functionality, but looks like Sightly JS Use APi only works on server side scripting. Even though I have included JQuery clientlibs, it still shows 'Reference error : '$' not defined'. Is there any way, we can make an ajax call in Sightly JS file?

Kindly note that this is for creating a JavaScript Object 'Data Layer' for holding meta data information about the website, which then will be tracked in Reports & Analytics.

I need to populate JSO(Data Layer) by making an ajax call to Sling Servlet for dynamically fetching user profile and other web site related information on page load.  I have been using JSP file for creating a JSO, but was thinking if we can leverage Javascript use api instead of using JSPs. Also, I am not sure if this is the right way to create a Data Layer in AEM 6.2. Please correct me if I am doing it in a wrong way.

Apperciate your help!

Thanks,

Jaya