我的问题是关于获取全局变量以将其分配给项目。
var cat; // clicked menu , reference for category, global variable
$(window).ready(function() {
jQuery(function() {
$('li.menuItem').click(function(e) {
cat = $('a', this).text();
$.ajax({
type: "GET",
timeout: 30000,
async: false,
cache: false,
global: false,
dataType: "text",
url: 'items.php?genre=' + cat,
success:function (data) {
items(data);// output number of items handled by function items() to make it global
}
});
});
});
function items(data) {
// We want this to show the "results" from the callback function.
console.log(data); // <-- this gives me the right number of items eatch time i click on different category
}
$('.pagination').pagination({
items: ??, <-- my issue is to assign the output data on the fly here,
itemsOnPage: 20,
cssStyle: 'light-theme',
currentPage: 1,
onPageClick: function(pageNumber) {
jQuery(".movies-list").html('loading...');
jQuery(".movies-list").load("connect.php?genre=" + cat + "&page=" + pageNumber);
}
});
});
我无法弄清楚如何在StackOverflow上进行一周或更长时间的Google搜索和冲浪而没有成功。 提前谢谢
答案 0 :(得分:0)
看起来您正在使用simplePagination.js,如果是这样,您可以使用updateItems
方法更新商品数量
function items(data) {
$('.pagination').pagination('updateItems', data);
}
答案 1 :(得分:0)
是的,我有一些外部参考,所以我发布在这里:
"maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"
"ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.js"
"maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"
"phpflow.com/demo/jquery_ajax_pagination_with_php_demo/dist/simplePagination.css"
"phpflow.com/demo/jquery_ajax_pagination_with_php_demo/dist/jquery.simplePagination.js"
"fontawesome.io/assets/font-awesome/css/font-awesome.css"
"seegatesite.com/bootstrap/css/bootstrap.min.css"
"seegatesite.com/bootstrap/css/simple-sidebar.css"
"seegatesite.com/bootstrap/js/jquery-1.11.2.min.js"