开发者

What does the "page" in "function loadData(page){}" mean in my jQuery Ajax?

开发者 https://www.devze.com 2023-03-29 19:34 出处:网络
I have the following code, and I\'m unsure of what the page in function loadData(page){} means? Also, the function is called later on, as loadData(1). If someone could please explain what this means,

I have the following code, and I'm unsure of what the page in function loadData(page){} means? Also, the function is called later on, as loadData(1). If someone could please explain what this means, it wou开发者_运维问答ld be greatly appreciated.

Function Definition (I think that's what it's called):

function loadData(page){
    loading_show();
    gallery_hide();                    
    $.ajax
    ({
        type: "GET",
        url: "new_arrivals_data.php",
        data: {page:page, imgs: value},
        success: function(msg)
        {
            $("#gallery_container").ajaxComplete(function(event, request, settings)
            {
                gallery_show();
                loading_hide();
                $("#gallery_container").html(msg);
            });
        }
    });
}

1st Function Call:

loadData(1);

2nd Function Call:

$('#gallery_container .pagination li.active').live('click',function(){
    var page = $(this).attr('p');
    loadData(page);
});           


It's a formal parameter representing a passed page number. It is used within the ajax call as part of the data to be sent to the server, here:

data: {page:page, imgs: value},

so if you do this:

loadPage(4);

your request will look like this:

new_arrivals_data.php?page=4&imgs=foo

This code:

var page = $(this).attr('p');
loadData(page);

calls loadData using the value assigned to the clicked element's 'p' attribute as its argument, which I suppose is a number.

0

精彩评论

暂无评论...
验证码 换一张
取 消