下面這段是判斷是否有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));}
回複討論(解決方案)
嚴格來說,這個判斷是檢測是否是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));}
你們很傷我的心哈,其實我明白,但是,你們答的都不對,敢許我一說答案,可能很多人會說,這還用說嗎,肯定的哈,這就是人類!所以答案我也不說了