CMSPAD中新加的一个小特性:JSON服务

很多界面效果库都是使用JSON来提供服务的,例如ExtJS等。因此,为了更好的兼容这些类库,我们为CMSPAD增加了一个JSON服务的特性。

同样地,它也是通过Portlet来对页面进行服务的:
[code]class SimplePortlet extends Portlet{

// 直接返回JSON字符串
public function jsonMyService1(){
return '{"hello":{"world":"JSON 测试"}}';
}

// 返回对象时,自动转换成JSON字符串
public function jsonMyService2(){
return array('hello' => array('world' => 'JSON 测试'));
}
}[/code]
而在客户端的代码中,我们可以这样调用:
[code]<script type="text/javascript">
function callJSON(o){
alert(o.hello.world);
}
</script>
<button type="button" οnclick="cmspad.json('SimplePortlet.myService1', callJSON);">JSON 测试</button>[/code]
下面看一下在实际应用中的JSON服务:我们在经典的[url=http://qwikioffice.com/desktop-demo/]ExtJS Desktop 2.0[/url]演示中,可以通过远程调用来进行对桌面进行配置。源代码如下:
[code]getDesktopConfig : function(){
// can call server for saved module id's
Ext.Ajax.request({
success: function(o){
var decoded = Ext.decode(o.responseText);

if(decoded.success){
this.initDesktopConfig(decoded.config);
}else{
// error
}
},
failure: function(){
// error
},
scope: this,
url: 'php/DesktopConfig.php'
});
}[/code]
上面的代码是使用Ext自带的AJAX组件进行远程调用的,而如果要使用CMSPAD的PHPortlet技术,该怎么办呢?[code]getDesktopConfig : function(){
var desktop = this;
cmspad.json('SimplePortlet.myDesktopExample', function(o){
desktop.initDesktopConfig(o.config);
});
}[/code]
这样,与ExtJS的整合即可完成。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值