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

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

  發(fā)布時(shí)間:2014-03-12 16:44:04   作者:佚名   我要評(píng)論
今天遇到一個(gè)getJSON的問(wèn)題,回調(diào)函數(shù)一直無(wú)法執(zhí)行,檢查了生成的json數(shù)據(jù)的格式絕對(duì)沒(méi)問(wèn)題,getJSON的js語(yǔ)法也沒(méi)問(wèn)題,但就是alert不出來(lái)傳回的數(shù)據(jù)。原來(lái)是phpcms的check_hash()函數(shù)對(duì)遠(yuǎn)程調(diào)用的方法進(jìn)行了安全驗(yàn)證,方法名前沒(méi)public_的都不能通過(guò)


復(fù)制代碼
代碼如下:

/**
* 檢查hash值,驗(yàn)證用戶(hù)數(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ù)進(jìn)行了hash驗(yàn)證,因此,現(xiàn)在方法是這樣寫(xiě)的:

復(fù)制代碼
代碼如下:

public function public_mobile_getjson_ids() {//publc是后來(lái)加上去的
$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是這樣寫(xiě)的:


復(fù)制代碼
代碼如下:

//顯示添加機(jī)型
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('沒(méi)有添加相關(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?。?!

相關(guān)文章

最新評(píng)論