2013-10-01 180 views
0

我正在嘗試使用我下載的插件將我的回調放入分頁插件中。使用Ajax和JSON進行分頁

我在正確的位置回調,但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'); 
     } 
    }); 
    }); 

回答

1

通過做$(initPagination);你不調用該函數。你正在將它包裝在jQuery函數中。

你怎麼稱呼它像任何其他功能:

initPagination(); 
+0

我曾經使用過initPagination(更新),但它仍然不無差錯工作 – Steven

+0

?或者你可以幫助更多的信息 –

+0

沒有錯誤。回調成功並傳遞給隱藏的div – Steven