一個小項目,用到了dwz,苦于官方少于維護且需要一部分前端技術一直沒有深挖,迫在眉睫,遇到了跟很多人一樣的問題,就是增刪改查不能局部刷新,苦惱啊。經多多放查找資料和翻閱源碼終于皇天不負有心。
項目使用TP3.1.3
需要做一下修改
找到 Thinkphp/lib/core/Action.class.php
查找 ajaxReturn 方法
注釋掉:
- if(func_num_args()>2) {// 兼容3.0之前用法
- $args = func_get_args();
- array_shift($args);
- $info = array();
- $info['data'] = $data;
- $info['info'] = array_shift($args);
- $info['status'] = array_shift($args);
- $data = $info;
- $type = $args?array_shift($args):'';
- }
然后在下方添加:
- if(method_exists($this,"ajaxAssign")) $this->ajaxAssign($data);//ajax賦值擴展
完整代碼如下:
- /**
- * Ajax方式返回數據到客戶端
- * @access protected
- * @param mixed $data 要返回的數據
- * @param String $type AJAX返回數據格式
- * @return void
- */
- protected function ajaxReturn($data,$type='') {
- // if(func_num_args()>2) {// 兼容3.0之前用法
- // $args = func_get_args();
- // array_shift($args);
- // $info = array();
- // $info['data'] = $data;
- // $info['info'] = array_shift($args);
- // $info['status'] = array_shift($args);
- // $data = $info;
- // $type = $args?array_shift($args):'';
- // }
- if(method_exists($this,"ajaxAssign")) $this->ajaxAssign($data);//ajax賦值擴展
- if(emptyempty($type)) $type = C('DEFAULT_AJAX_RETURN');
- switch (strtoupper($type)){
- case 'JSON' :
- // 返回JSON數據格式到客戶端 包含狀態信息
- //header('Content-Type:application/json; charset=utf-8');
- header('Content-Type:text/html; charset=utf-8'); //zhanghuihua
- exit(json_encode($data));
- case 'XML' :
- // 返回xml格式數據
- header('Content-Type:text/xml; charset=utf-8');
- exit(xml_encode($data));
- case 'JSONP':
- // 返回JSON數據格式到客戶端 包含狀態信息
- header('Content-Type:application/json; charset=utf-8');
- $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER');
- exit($handler.'('.json_encode($data).');');
- case 'EVAL' :
- // 返回可執行的js腳本
- header('Content-Type:text/html; charset=utf-8');
- exit($data);
- default :
- // 用于擴展其他返回格式數據
- tag('ajax_return',$data);
- }
- }
在任意一出添加:
- protected function ajaxAssign(&$result){
- $result['statusCode'] = $result['status'];
- $result['navTabId'] = $_REQUEST['navTabId'];
- $result['message']=$result['info'];
- }
退出DWZ,重新登錄 再試試吧!
新聞熱點
疑難解答