$(function(){ //======================= // ajax相關 start //======================= var contentBox = $("#NewsBox"), ajaxUrl = Project_Country + contentBox.data("url"), pageBox = $(".bottom-page"), newsTypeID = $(".news-wrapper").data("id") //換頁 $(document).on("click", ".bottom-page .item", function(){ let _this = $(this), page = _this.find(".page").data("page") getNewsList(ajaxUrl, contentBox, pageBox, { "page": page, "year": $('#yearSelect').val(), "id": newsTypeID }); }); //選擇類別 $(document).on("change", ".selectbox-select", function(){ let _this = $(this), val = _this.val() getNewsList(ajaxUrl, contentBox, pageBox, { "page": 1, "year": val, "id": newsTypeID }) }) function getNewsList(ajaxUrl,contentBox,pageBox,data){ $.ajax({ url: ajaxUrl, type: "POST", cache: false, async: true, dataType: 'json', data: data, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ contentBox.html(d.items) pageBox.html(d.pagebox) } }) } //======================= // ajax相關 end //======================= })