我的问题是如何获取全局变量并将其分配给项目。
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 上进行了一周或更长时间的谷歌搜索和冲浪,但没有成功。 预先感谢您
最佳答案
看起来您正在使用 simplePagination.js ,如果是这样,您可以使用 updateItems
方法来更新项目数量
function items(data) {
$('.pagination').pagination('updateItems', data);
}
关于javascript - jquery 的 ajax 全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38909386/