【问题标题】:Pagination using Ajax with JSON使用 Ajax 和 JSON 进行分页
【发布时间】:2013-10-07 13:43:06
【问题描述】:

我正在尝试使用我下载的插件将回调放入分页插件中。

我在正确的位置有回调,但是 pageselectCallback 函数在复制第一页记录并将其放入 div 的位置未初始化。

     // This demo shows how to paginate elements that were loaded via AJAX
  // It's very similar to the static demo.

/**
* Callback function that displays the content.
*
* Gets called every time the user clicks on a pagination link.
*
* @param {int}page_index New Page index
* @param {jQuery} jq the container with the pagination links as a jQuery object
*/
function pageselectCallback(page_index, jq){
    var new_content = $('#hiddenresult div.result:eq('+page_index+')').clone();
    $('#Searchresult').empty().append(new_content);
    return false;
   }

    /** 
   * Callback function for the AJAX content loader.
    */
    function initPagination() {
    $('#answer').text('This is a call to see that it is initiated');
    var num_entries = $('#hiddenresult div.result').length;
    // Create pagination element
    $("#Pagination").pagination(num_entries, {
    num_edge_entries: 2,
    num_display_entries: 8,
    callback: pageselectCallback,
    items_per_page:1
    });
}

// Load HTML snippet with AJAX and insert it into the Hiddenresult element
// When the HTML has loaded, call initPagination to paginate the elements        
$(document).ready(function() {
   $.ajax({ 
        url: "https://api.eancdn.com/ean-services/rs/hotel/v3/list?cid=55505&minorRev=99&apiKey=cbrzfta369qwyrm9t5b8y8kf&locale=en_AU&city=Brisbane&stateProvinceCode=QL&countryCode=AU&&numberOfResults=10&_type=json",
       dataType: "jsonp",
        success: function(data) {
        var StrHotelListResponse = data.HotelListResponse.HotelList.HotelSummary;
            $.each(StrHotelListResponse, function(index, value) {
            var StrlowRate = parseInt(value.lowRate);
               $('#hiddenresult').append('<div class="hotel-name">' + value.name + '</div>');
               $('#hiddenresult').append('<div class="hotel-rating">' + value.hotelRating + '</div>');
               $('#hiddenresult').append('<div class="hotel-address">' + value.address1 + ' ' + value.city + ', ' + value.stateProvinceCode + ' ' + value.postalCode  + '</div>');
        });

              initPagination();
          },
       error: function(e) {
           console.log(e.message);
           //alert('no');
       }
   });
   });

【问题讨论】:

    标签: javascript jquery ajax json pagination


    【解决方案1】:

    通过$(initPagination); 你没有调用该函数。您将其包装在 jQuery 函数中。

    您需要像调用其他任何函数一样调用它:

     initPagination();
    

    【讨论】:

    • 我只用 initPagination() 更新了,但还是不行
    • 没有错误?或者您能提供更多信息吗
    • 没有错误。回调成功,传给隐藏的div
    • initPagination(); 中添加警报或控制台日志以确保它正在运行。如果是这样,那么其中的代码有问题,可能您没有针对正确的元素。
    猜你喜欢
    • 2017-08-17
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 2014-05-13
    相关资源
    最近更新 更多