我的問題是關於獲取全局變量分配給項目。ajax全局變量與jquery
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);
}
});
});
我無法弄清楚如何現在解決它是一個星期或更長時間的谷歌搜索,並沒有成功在計算器上衝浪。 預先感謝您
,其是用於分頁插件,是它的[simplePagination](http://flaviusmatis.github.io/simplePagination.js/) –
刪除 「}」 的console.log(數據)之後再更換??與數據 –
也會很好,如果你告訴我們你console.log結果 –