简体   繁体   English

AJAX调用CQ5组件

[英]AJAX call in CQ5 component

I am creating a component that needs to fetch dynamic data on change of a dropdown. 我正在创建一个组件,需要在下拉列表更改时获取动态数据。

Is there a way to place an ajax call from the component to an OSGi bundle to get the data dynamically at run time ? 有没有办法将ajax调用从组件放到OSGi包中以在运行时动态获取数据? Any sample code will be helpful. 任何示例代码都会有所帮助。

I got stuck at the URL that will be used to placed the call. 我陷入了用于拨打电话的网址。

Exposing your service as a Servlet by using the SlingServlet annotation should do the trick. 使用SlingServlet注释将服务公开为Servlet应该可以解决问题。 The path argument would be your relative URL. path参数将是您的相对URL。

@SlingServlet(paths = "/bin/imageratio", extensions = "json")
public class ImageRatioServlet extends SlingSafeMethodsServlet {

    @Override
    protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException {
 ....

See the documentation and the mentioned post for more details: http://sling.apache.org/documentation/the-sling-engine/servlets.html http://blogs.adobe.com/aaa/2012/09/cq-tips-and-tricks-1-how-to-define-a-slingservlet-cq5-5-5-6.html 有关详细信息,请参阅文档和上述帖子: http//sling.apache.org/documentation/the-sling-engine/servlets.html http://blogs.adobe.com/aaa/2012/09/cq-提示-和技巧-1的how-to-定义-A-slingservlet-cq5-5-5-6.html

In your ajax call,say for suppose if you give url as apps/yourproject/sampleservlet 在你的ajax调用中,假设您将url作为apps / yourproject / sampleservlet给出

Give the same url at @SlingServlet(paths = "apps/yourproject/sampleservlet", extensions = "json") as specified by Thomas 在Thomas指定的@SlingServlet(paths =“apps / yourproject / sampleservlet”,extensions =“json”)中提供相同的URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM