php中json_encode实现json

[ 2009-11-16 09:32:34 | 作者: admin ]
字号: | |
/**
           *(ajax)获取列表
           */
         function getLists($uid){
                Configure::write('debug',0);
                $this->layout = 'ajax';
                $albums = $this->Album->findAll("user_id =$uid",array('id','name'));
                $albums =CommFun::stripslashes_deep($this->__arrayChange($albums,'name'));
                $albums =CommFun::iconvDeep($albums,'GBK','UTF-8');
                $albums = ! empty($albums) ? $albums : '';
                $msg=json_encode($albums);
                echo $msg;
                exit();
         }
        

js:用了prototype
var id;
var url;
/*
* @param url 请求链接,
* @param showid 显示的id号
* @param showResponse 处理方法
* @param args 参数
*/
function showdata(url,showid,showResponse,args){
         id = showid;
         this.url = url;
         var myAjax = new Ajax.Request(
                     url,
                     {
                     method:'post',
                     parameters:args,
                     onSuccess:showResponse
                     }
                     );
}
/*清除select选项*/
function clearList(id){
     $(id).options.length = 0;
}
/*接受json数据,显示下拉列表项*/
function showList(msg){
         var resp = msg.responseText;
         var func = new Function("return "+resp);
         var objt = func();
         clearList(id);
         if(objt.length <=0){return;}
         $(id).options.add(new Option('请选择...',''));
         for(var i in objt){
                $(id).options.add(new Option(objt[i],i));
         }
}
[最后修改由 admin, 于 2009-11-16 09:35:02]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1320

这篇日志没有评论。

此日志不可发表评论。