加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

多个Ajax调用liferay portlet

发布时间:2020-12-15 22:52:37 所属栏目:百科 来源:网络整理
导读:我有liferay portlet,我需要在很大程度上依赖于 AJAX调用.所以我需要多次调用serveResource方法.一种方法是我可以使用URL传递参数,然后根据该参数区分请求. 但在我的情况下,我必须多次调用serveResource,因为该方法很难维护. 有没有这样做的框架?使用哪些代
我有liferay portlet,我需要在很大程度上依赖于 AJAX调用.所以我需要多次调用serveResource方法.一种方法是我可以使用URL传递参数,然后根据该参数区分请求.

但在我的情况下,我必须多次调用serveResource,因为该方法很难维护.
有没有这样做的框架?使用哪些代码变得可维护.

解决方法

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

试试下面的代码
在jsp中

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

在jsp中调用ajax

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();
                });
        });

在controller / java类中

@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
    }

希望上面的代码片段可以帮助你,你得到你想要的!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读