CQ5组件中的AJAX调用

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 ? 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. The path argument would be your relative 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

In your ajax call,say for suppose if you give url as apps/yourproject/sampleservlet

Give the same url at @SlingServlet(paths = "apps/yourproject/sampleservlet", extensions = "json") as specified by Thomas