Javascript 使用Ajax和JSON进行分页

Javascript 使用Ajax和JSON进行分页,javascript,jquery,ajax,json,pagination,Javascript,Jquery,Ajax,Json,Pagination,我正在尝试使用我下载的插件将我的回调放入分页插件 我将回调放在正确的位置,但是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 conten

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

我将回调放在正确的位置,但是
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');
       }
   });
   });
//此演示演示如何对通过AJAX加载的元素进行分页
//它与静态演示非常相似。
/**
*显示内容的回调函数。
*
*每次用户单击分页链接时调用。
*
*@param{int}page_index新建页面索引
*@param{jQuery}jq将分页链接作为jQuery对象的容器
*/
函数pageselectCallback(页面索引,jq){
var new_content=$('#hiddensult div.result:eq('+page_index+')).clone();
$('#Searchresult').empty().append(新内容);
返回false;
}
/** 
*AJAX内容加载器的回调函数。
*/
函数初始化分页(){
$(“#应答”).text('这是一个确认它已启动的调用');
var num_entries=$('#hiddenresult div.result').length;
//创建分页元素
$(“#分页”)。分页(num#u条目{
数量\u边\u条目:2,
显示条目数:8,
callback:pageselectCallback,
每页项目:1
});
}
//使用AJAX加载HTML代码段并将其插入Hiddenresult元素
//加载HTML后,调用initPagination对元素进行分页
$(文档).ready(函数(){
$.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",
数据类型:“jsonp”,
成功:功能(数据){
var StrHotelListResponse=data.hotellistsresponse.HotelList.HotelSummary;
$.each(StrHotelListResponse,函数(索引,值){
var StrlowRate=parseInt(value.lowRate);
$('#hiddenresult').append(''+value.name+'');
$('hiddenresult').append(''+value.hotelRating+'');
$(“#hiddenresult”).append(“”+value.address1+“”+value.city+“”,“”+value.stateProvinceCode+“”+value.postalCode+“”);
});
初始化分页();
},
错误:函数(e){
控制台日志(e.message);
//警告(“否”);
}
});
});
通过执行
$(初始分页)您没有调用该函数。您正在将其包装到jQuery函数中

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

 initPagination();

我只更新了initPagination(),但它仍然不能正常工作,没有错误吗?或者你能帮我提供更多的信息吗?没有错误。回调成功并传递给隐藏分区,在
initPagination()中添加警报或控制台日志以确保它正在运行。如果是这样的话,那么里面的代码就有问题了,可能您没有针对正确的元素。