欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHPCMS通過getJSON調(diào)用的地址回調(diào)函數(shù)一直無法執(zhí)行

  發(fā)布時間:2014-03-11 16:42:01   作者:佚名   我要評論
遇到一個getJSON的問題,回調(diào)函數(shù)一直無法執(zhí)行,檢查所有的都沒有問題,但就是alert不出來傳回的數(shù)據(jù),有類似情況的朋友可以參考下本文
今天遇到一個getJSON的問題,回調(diào)函數(shù)一直無法執(zhí)行,檢查了生成的json數(shù)據(jù)的格式絕對沒問題,getJSON的js語法也沒問題,但就是alert不出來傳回的數(shù)據(jù)。原來是phpcms的check_hash()函數(shù)對遠程調(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)用遠程地址,方法前加上public?。。?

相關(guān)文章

最新評論