Home > Backend Development > PHP Tutorial > 关于ajax的判断

关于ajax的判断

WBOY
Release: 2016-06-23 13:32:54
Original
1047 people have browsed it

下面这段是判断是否有ajax请求的
不过实在不好理解
能不能注释一下

//判断是否有ajax请求$act = !empty($_GET['act']) ? $_GET['act'] : '';if ($act == 'cat_rec'){    $rec_array = array(1 => 'best', 2 => 'new', 3 => 'hot');    $rec_type = !empty($_REQUEST['rec_type']) ? intval($_REQUEST['rec_type']) : '1';    $cat_id = !empty($_REQUEST['cid']) ? intval($_REQUEST['cid']) : '0';    include_once('includes/cls_json.php');    $json = new JSON;    $result   = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id);    $children = get_children($cat_id);    $smarty->assign($rec_array[$rec_type] . '_goods',      get_category_recommend_goods($rec_array[$rec_type], $children));    // 推荐商品    $smarty->assign('cat_rec_sign', 1);    $result['content'] = $smarty->fetch('library/recommend_' . $rec_array[$rec_type] . '.lbi');    die($json->encode($result));}
Copy after login


回复讨论(解决方案)

严格来说,这个判断是检测是否是get请求的。就是获取get参数,然后判断,有什么理解不了的。

不知道你是哪边不清楚还是全部不清楚 这个就是简单的http get访问根据获取的信息输出对应的数据。

//判断是否有get请求,并且获取请求参数中的act值,此处不一定是ajax调用   正常的浏览器调用也是可以的$act = !empty($_GET['act']) ? $_GET['act'] : '';// 如果get请求参数act为cat_rec,则执行if里面的代码,如果不等于则忽略if ($act == 'cat_rec'){    $rec_array = array(1 => 'best', 2 => 'new', 3 => 'hot');    $rec_type = !empty($_REQUEST['rec_type']) ? intval($_REQUEST['rec_type']) : '1';    $cat_id = !empty($_REQUEST['cid']) ? intval($_REQUEST['cid']) : '0';    include_once('includes/cls_json.php');    $json = new JSON;    $result   = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id);     $children = get_children($cat_id);    $smarty->assign($rec_array[$rec_type] . '_goods',      get_category_recommend_goods($rec_array[$rec_type], $children));    // 推荐商品    $smarty->assign('cat_rec_sign', 1);    $result['content'] = $smarty->fetch('library/recommend_' . $rec_array[$rec_type] . '.lbi');    die($json->encode($result));}
Copy after login

你们很伤我的心哈,其实我明白,但是,你们答的都不对,敢许我一说答案,可能很多人会说,这还用说吗,肯定的哈,这就是人类!所以答案我也不说了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template