对于JQuery的Ajax调用后循环JQuery、Ajax

由网友(14.我没那么多介意)分享简介:我想循环AJAX调用后返回的数据被成功添加结果的分页插件。 I am trying to loop the data returned after ajax call is success and adding the result to pagination plugin.下面是我的code:var images...

我想循环AJAX调用后返回的数据被成功添加结果的分页插件。

I am trying to loop the data returned after ajax call is success and adding the result to pagination plugin.

下面是我的code:

 var imagesPerPage = 2, pageNumber = 1;
  var pagesContainer = $('#pagesContainer'),
  imagesInPage = 0,
  divPage = $("#p1");

    $.ajax({
           type: "POST",
           url: "Default.aspx/GetImages",
           data:{},
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           success: function (response) {

             //Here goes my for loop                    

           }
      });

这是我的for循环,我需要从的webmethod和环路他们获得的图像,并添加到分页。

This is my for loop where I need to get the images from webmethod and loop them and add to the pagination.

 for (i = 0; i < response.d.length; i++) {
          if (imagesInPage >= imagesPerPage) {
          imagesInPage = 1;
          pageNumber += 1;
          divPage = $('<div/>', { id: "p" + pageNumber }).addClass('pagedemo').hide().appendTo(pagesContainer);
          } else {
          imagesInPage += 1;
          }
}

下面是我的分页默认配置:

Here is my pagination default configuration:

 $("#pagination").paginate({
              count: pageNumber,
              start: 1,
              display: Math.min(7, pageNumber),
              border: true,
              border_color: '#fff',
              text_color: '#fff',
              background_color: 'black',
              border_hover_color: '#ccc',
              text_hover_color: '#000',
              background_hover_color: '#fff',
              images: false,
              mouse: 'press',
              onChange: function (page) {
              $('#paginationdemo ._current').removeClass('_current').hide();
              $('#p' + page).addClass('_current').show();
        }
  }); //pagination

现在我的问题是,当我试图让一个图像的响应它没有显示我的形象以及在pagination.If它不止一个,那么它开始显示我的分页和形象。

Now my problem is when I try to get the response of one Image it is not showing me the image as well as the pagination.If it is more than one then it starts showing me the pagination and image.

截图

因此​​,谁能说我在哪里,我要去哪里呢?

So can anyone say me where am I going wrong?

推荐答案

这是你的分页问题,​​最近我遇到了同样的问题。为了解决这个问题,你需要一个条件。检查响应的长度。如果它是1,则加一些默认值和,将工作。

This is your pagination problem recently i met with the same problem. To fix this you will need a condition. check the length of response. if it is 1 then add some default values and that will work.

阅读全文

相关推荐

最新文章