Ajax在portlet配置jsp页面(liferay 6.2)中不起作用 [英] Ajax not working in the portlet configuration jsp page (liferay 6.2)

查看:65
本文介绍了Ajax在portlet配置jsp页面(liferay 6.2)中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 MVCPortlet(Liferay 6.2).

此ajax调用是否可以在我的portlet的常规jsp上运行,但在portlet的配置页面上不起作用(在您单击右上角然后单击配置和选项"时打开的jsp),是否有任何原因. /p>

在这种情况下,portletURL会正确显示(警报),JS返回成功,但控制器从未收到客户端请求.

这是ajax调用:

$.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');
    }
});

同样,此代码在另一个jsp上也能很好地工作.

这会给任何人敲响钟声吗? 预先感谢.

解决方案

我在Liferay 7.0.x中遇到了同样的问题,并且找到了可以应用于6.2的有效解决方案,但是我没有用于测试的实例.

您必须使用Java代码生成资源网址.例如:

LiferayPortletURL resourceURL = (LiferayPortletURL) renderResponse.createResourceURL();
resourceURL.setPortletId(ParamUtil.getString(request, "portletResource"));
resourceURL.setResourceID("yourId");

然后使用resourceURL.toString()生成URL.必须在portlet类中实现serverResource.

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.

解决方案

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.

这篇关于Ajax在portlet配置jsp页面(liferay 6.2)中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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