广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >PHPCMS通过getJSON调用的地址回调函数一直无法执行
  • 866
分享到

PHPCMS通过getJSON调用的地址回调函数一直无法执行

PHPCMSgetJSON 2022-06-12 01:06:35 866人浏览 泡泡鱼
摘要

今天遇到一个getJSON的问题,回调函数一直无法执行,检查了生成的json数据的格式绝对没问题,getJSON的js语法也没问题,但就是alert不出来传回的数据。原来是PHPcms的check_hash()函数对远程

今天遇到一个getJSON的问题,回调函数一直无法执行,检查了生成的json数据的格式绝对没问题,getJSON的js语法也没问题,但就是alert不出来传回的数据。原来是PHPcms的check_hash()函数对远程调用的方法进行了安全验证,方法名前没public_的都不能通过。


复制代码代码如下:

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给函数进行了hash验证,因此,现在方法是这样写的:


复制代码代码如下:

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是这样写的:


复制代码代码如下:

//显示添加机型

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('没有添加相关文章');

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里面调用远程地址,方法前加上public啊!!

--结束END--

本文标题: PHPCMS通过getJSON调用的地址回调函数一直无法执行

本文链接: https://www.lsjlt.com/news/31777.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作