phpcms调用getJSON无法返回json数据的解决方法

phpcms调用getJSON无法返回json数据的解决方法,第1张

phpcms调用getJSON无法返回json数据的解决方法

今天遇到一个getjson的问题,回调函数一直无法实现。检查形成的jsON数据的格式没有问题,getJSON的JS语法也没有问题,但是是警报传输的数据。原来phpcms的check_hash()函数认证了远程控制使能模式,没有public_的模式名是无法基于它的。


复制代码如下:
/**
*检查哈希值并验证客户数据的安全系数
*/
Final私有函数Check_hash(){
if(preg_match('/public&;ROUTE_C=='index'||in_array(ROUTE_A,array('login')){
returntrue;
}
if(isset($_GET['PC_hash'])&;&$_SESSION['pc_hash']!=“”&;&($_SESSION['PC_hash']==$_GET['PC_hash']){
返回true
}elseif(isset($_POST['PC_hash'])&;&$_SESSION['pc_hash']!=“”&;&($_SESSION['PC_hash']==$_POST['PC_hash']){
返回true
}else{
showmessage(L('hash_check_false'),HTTP_REFERER);
}
}

Phpcms已经对涵洞进行了哈希认证,所以现在的写法是这样的:

复制代码如下:
公共函数public_mobile_GETJSON_ids(){//public是后面加上的
$modelid=intval($_GET
$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="idIN($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($其中,'id,title');
foreach($datasas$_v){
$_v['sid']='v'。$_v['id'];
if(strtolower(CHARSET)=='gbk')$_v['type_name']=iconv('gbk','utf-8',$_v['type_name']);
$infos[]=$_v;
}
echoJSON_encode($infos);
}
}

GetjsON,JS的一部分,是这样写的:


复制代码如下:
/显示信息加型号
函数Show_MobileType(ModelID,ID){
$。GetJSON("?m=内容&c=内容&a=public_mobile_getJSON_ids&;modelid="modelid"&id="id,function(JSON){
varnewrelation_ids='';
if(JSON==null){
alert('不添加相关文章');
返回false
}
$。each(json,function(i,n){
newrelation_ids="<;liid='"n.sid"'><span>n.type_name"</span>。<ahref='JavaScript:;'class='close'onclick=\"remove_relation(""n.sid"',"n.id")\">;</a>;</李>";
});

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

就好。注意phpcms中启用的远程控制的详细地址,方法前加public!!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/772948.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-03
下一篇 2022-05-03

发表评论

登录后才能评论

评论列表(0条)

保存