我正在使用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
发布评论