您的位置:首页 > Web前端 > JQuery

liferay中使用Jquery返回json对象处理

2008-11-11 09:41 429 查看
1. 引入js。
参见liferay-portlet.xml
在配置<portlet>时,其中有一项<header-portlet-javascript>

<header-portlet-javascript>/html/portlet/mail/packed.js</header-portlet-javascript>
在dtd中这样解释
Set the path of JavaScript that will be referenced in the page's header relative to the portlet's context path.
具体的装载过程在PortletLocalServiceImpl.java中的_readLiferayPortletXML方法中可以看到
2. Ajax方法
var xHR = jQuery.ajax (
{ //定义访问url,对应struts的配置文件
url: themeDisplay.getPathMain() + "/mail/action",
//参数设置
data: {cmd: "getRecipients", data: data.value},
//返回类型
dataType: 'json',
async: false
}
);
3. Action返回josn
在action中通过JSONArray构建json对象返回,具体可参见MailAction.java
Action必须继承JSONAction,覆写父类方法getJSON()
4. 客户端获取并处理
获取返回内容,转化为josn格式
var jsonObj = Liferay.Util.toJSONObject(xmlHttpReq.responseText);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: