问题
Working on a MVCPortlet (Liferay 6.2).
Is there any reason why this ajax call works on a regular jsp of my portlet, but does not work on the config page of the portlet (the jsp that opens when you click top right corner and then configuration and option).
In this case, the portletURL
is correctly displayed (alert), the JS returns success but the controller never received the client request.
Here's the ajax call:
$.ajax({
url: portletURL,
type: 'POST',
dataType: 'text',
cache: false,
data: {
test: test
},
success: function(data) {
alert('success ajax');
},
error: function(http, message, exc) {
alert('error ajax');
}
});
Again, this code works perfectly an another jsp.
Does this ring a bell to anybody? Thanks in advance.
回答1:
I had the very same problem. Tried both liferay-portlet:resourceURL portletConfiguration="true"
and portlet:resourceURL
, also with manual parsing and modifying the url before sending. The resource serving method (whether implementation of the serveResource
, or completely new method using either Spring MVC or Liferay MVC (implementation class of MVCPortlet
)), none worked in configuration mode.
The solution for me was to avoid resource serving at all and instead choose action phase (p_p_lifecycle=1). It is completely doable in AJAX, just had to override processAction
method in my DefaultConfigurationAction
implementation class.
Hope this saves someone the countless hours I spent with it.
回答2:
I have the same problem in Liferay 7.0.x and I found a working solution which could be applied to 6.2 but I have not an instance for test.
You have to generate the resource url with java code. As an example:
LiferayPortletURL resourceURL = (LiferayPortletURL) renderResponse.createResourceURL();
resourceURL.setPortletId(ParamUtil.getString(request, "portletResource"));
resourceURL.setResourceID("yourId");
Then use the resourceURL.toString()
to generate the URL. The serverResource has to be implemented in the portlet class.
来源:https://stackoverflow.com/questions/33584951/ajax-not-working-in-the-portlet-configuration-jsp-page-liferay-6-2