關於ajax的判斷

來源:互聯網
上載者:User
下面這段是判斷是否有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));}

你們很傷我的心哈,其實我明白,但是,你們答的都不對,敢許我一說答案,可能很多人會說,這還用說嗎,肯定的哈,這就是人類!所以答案我也不說了

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.