国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > PhpCMS > 正文

phpcms調(diào)用getJSON無法返回json數(shù)據(jù)的解決方法

2024-07-09 22:53:46
字體:
供稿:網(wǎng)友

點評:今天遇到一個getJSON的問題,回調(diào)函數(shù)一直無法執(zhí)行,檢查了生成的json數(shù)據(jù)的格式絕對沒問題,getJSON的js語法也沒問題,但就是alert不出來傳回的數(shù)據(jù)。原來是phpcms的check_hash()函數(shù)對遠(yuǎn)程調(diào)用的方法進行了安全驗證,方法名前沒public_的都不能通過

 

 

 

復(fù)制代碼

代碼如下:


/**
* 檢查hash值,驗證用戶數(shù)據(jù)安全性
*/
final private function check_hash() {
if(preg_match('/^public_/', ROUTE_A) || ROUTE_M =='admin' && ROUTE_C =='index' || in_array(ROUTE_A, array('login'))) {
return true;
}
if(isset($_GET['pc_hash']) && $_SESSION['pc_hash'] != '' && ($_SESSION['pc_hash'] == $_GET['pc_hash'])) {
return true;
} elseif(isset($_POST['pc_hash']) && $_SESSION['pc_hash'] != '' && ($_SESSION['pc_hash'] == $_POST['pc_hash'])) {
return true;
} else {
showmessage(L('hash_check_false'),HTTP_REFERER);
}
}

 

phpcms給函數(shù)進行了hash驗證,因此,現(xiàn)在方法是這樣寫的:
 

復(fù)制代碼

代碼如下:


public function public_mobile_getjson_ids() {//publc是后來加上去的
$modelid = intval($_GET['modelid']);
$id = intval($_GET['id']);
$this->db->set_model($modelid);
$tablename = $this->db->table_name;
$this->db->table_name = $tablename.'_data';
$r = $this->db->get_one(array('id'=>$id),'mobile_type');

if($r['mobile_type']) {
$relation = str_replace('|', ',', $r['mobile_type']);
$relation = trim($relation,',');
$where = "id IN($relation)";
$infos = array();
$this->mobile_db = pc_base::load_model ( 'mobile_type_model' );
$datas = $this->mobile_db->select($where,'id,type_name');
//$this->db->table_name = $tablename;
//$datas = $this->db->select($where,'id,title');
foreach($datas as $_v) {
$_v['sid'] = 'v'.$_v['id'];
if(strtolower(CHARSET)=='gbk') $_v['type_name'] = iconv('gbk', 'utf-8', $_v['type_name']);
$infos[] = $_v;
}
echo json_encode($infos);
}
}

 

js部分的getJSON是這樣寫的:

 

復(fù)制代碼

代碼如下:


//顯示添加機型
function show_mobiletype(modelid,id) {
$.getJSON("?m=content&c=content&a=public_mobile_getjson_ids&modelid="+modelid+"&id="+id, function(json){
var newrelation_ids = '';
if(json==null) {
alert('沒有添加相關(guān)文章');
return false;
}
$.each(json, function(i, n){
newrelation_ids += "<li id='"+n.sid+"'>·<span>"+n.type_name+"</span><a href='javascript:;' class='close' onclick=/"remove_relation('"+n.sid+"',"+n.id+")/"></a></li>";
});

$('#mobile_type_text').html(newrelation_ids);
}); 
}


就好了。要注意phpcms里面調(diào)用遠(yuǎn)程地址,方法前加上public啊!!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 绩溪县| 贵溪市| 曲麻莱县| 长乐市| 枣阳市| 綦江县| 海宁市| 安顺市| 从江县| 钟山县| 平罗县| 丹巴县| 新丰县| 恩施市| 泰来县| 清苑县| 定边县| 乡宁县| 黔西| 利津县| 乾安县| 沐川县| 册亨县| 睢宁县| 洪江市| 龙州县| 宾川县| 铜川市| 天祝| 疏附县| 茶陵县| 柳州市| 凉城县| 石渠县| 开化县| 永顺县| 当阳市| 望城县| 诸城市| 新乡市| 枞阳县|