簡體   English   中英

帶jquery的ajax全局變量

[英]ajax global variable with 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);

        }
    });
});

我無法弄清楚如何解決它現在已經過一周或更長時間的Google搜索並在StackOverflow上沖浪而沒有成功。 先感謝您

看起來您正在使用simplePagination.js ,如果是這樣,您可以使用updateItems方法更新項目數

function items(data) {
    $('.pagination').pagination('updateItems', data);
}

是的,我有一些外部參考,所以我發布在這里:

"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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM