多个Ajax调用liferay Portlet [英] Multiple Ajax calls liferay portlets

查看:73
本文介绍了多个Ajax调用liferay Portlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用liferay Portlet,我需要高度依赖AJAX调用.因此,我需要多次调用serveResource方法.一种方法是,我可以通过URL传递参数,然后根据该参数区分请求.

I am having liferay portlet and I need to heavily depend upon the AJAX calls. So I need to make multiple calls to serveResource method. One way to do the same is that I can pass a parameter with the URL and then differentiate the request according to that parameter.

但是在我的情况下,我必须多次调用serveResource,由于该方法将很难维护. 有没有这样做的框架?使用该代码可维护代码.

But in my case I have to call serveResource so many times due to which the method will be difficult to maintain. Is there any framework to do so? Using which the code becomes maintainable.

推荐答案

使用Spring MVC框架并根据您在控制器中的业务逻辑/用户操作调用不同的方法,

Use Spring MVC framework and call different method based on your business logic/user action in controller,

尝试以下代码 在jsp中

Try below code in jsp

<portlet:resourceURL var="loadContents" id="loadContents"></portlet:resourceURL>
<portlet:resourceURL var="loadCategories" id="loadCategories"></portlet:resourceURL>

jsp中的ajax调用

ajax call in jsp

AUI().ready(
        function(A) {            
            A.use('aui-io-request', 
                    function(aui) {
                    A.io.request("<%=loadContents%>", {
                        autoLoad : false,
                        cache : false,
                        dataType : 'json',
                        data:{},
                        method:'POST',
                        on : {
                            success : function(event, id, xhr) {
                                var response = this.get('responseData');
                                 // add logic here after response
                            }
                        }
                    }).start();
                });
        });

在控制器/Java类中

in controller/ java class

    @ResourceMapping("loadCategories")
    public void loadCategories(final ResourceRequest resourceRequest, final ResourceResponse resourceResponse)
    {
         // your business logic goes here
    }

    @ResourceMapping("loadContents")
    public void loadContents(final ResourceRequest resourceRequest, final ResourceResponse resourceResponse)
    {
         // your business logic goes here
    }

希望以上代码片段将对您有所帮助,您将获得所需的内容!!!

hope above code snippets will help you and you get what you were looking for!!!

这篇关于多个Ajax调用liferay Portlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆