Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有jquery的ajax全局变量_Javascript_Jquery - Fatal编程技术网

Javascript 带有jquery的ajax全局变量

Javascript 带有jquery的ajax全局变量,javascript,jquery,Javascript,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

我的问题是获取全局变量以将其分配给项

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);

        }
    });
});
var cat;//单击菜单,类别参考,全局变量
$(窗口).ready(函数(){
jQuery(函数(){
$('li.menuItem')。单击(函数(e){
cat=$('a',this).text();
$.ajax({
键入:“获取”,
超时:30000,
async:false,
cache:false,
全球:错,
数据类型:“文本”,
url:'items.php?流派='+cat,
成功:功能(数据){
items(data);//输出函数items()处理的全局项目数
}
});
});
});
功能项(数据){
//我们希望它显示回调函数的“结果”。

console.log(data);//看起来您正在使用,如果是,您可以使用
updateItems
方法更新项目数

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

看起来您正在使用,如果是,您可以使用
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"

是的,没错,我有一些外部参考,所以我在这里发布它们:

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

哪一个是使用的分页插件,是在console.log(数据)之后删除“}”,然后用数据替换??如果您向我们展示您的console.log result,那将非常好,它是使用的分页插件,是在console.log(数据)之后删除“}”然后用数据替换??如果您向我们展示您的console.log,那就太好了result@Jakozi不确定这是什么意思?只需将您的函数替换为我在上面发布的函数,然后查看它是否是这样工作的:函数项(数据){//我们希望它显示回调函数的“结果”。$('.pagination')。pagination('updateItems',data);}$('.pagination').pagination({items:222,itemsOnPage:20,csssstyle:'light theme',currentPage:1,onPageClick:function(pageNumber){jQuery(.movies list”).html('loading…');jQuery(.movies list”).load(“connect.php?genre=“+cat+”&page=“+pageNumber);}}}}”);未捕获类型错误:$(…)。分页不是一个function@Jakozi尝试
jQuery('.pagination')。pagination('updateItems',data);
相同的错误未捕获类型错误:jQuery(…).分页不是一个好方法function@Jakozi不确定这是什么意思?只需将您的函数替换为我在上面发布的函数,看看它是否是这样工作的:函数项(数据){//我们希望它显示回调函数的“结果”。$('.pagination').pagination('updateItems',data);}$('.pagination').pagination({items:222,itemsOnPage:20,csssstyle:'light theme',当前页面:1,onPageClick:function(pageNumber){jQuery(“.movies list”).html('load…');jQuery(.movies list”).load(“connect.php?genre=“+cat+”&page=“+pageNumber”);}}});});未捕获的类型错误:$(…)。分页不是function@Jakozi尝试
jQuery('.pagination')。pagination('updateItems',data);
uncaughttypeerror:jQuery(…)。pagination不是一个函数