简体   繁体   English

jQuery-无限滚动设置标头ajax分页

[英]Jquery - Infinite Scroll set header ajax pagination

I'm using jQuery Infinite scroll plugin for pagination. 我正在使用jQuery Infinite滚动插件进行分页。 The pagination URL is dynamic as it is returned from API. 分页URL是动态的,因为它是从API返回的。 This code works till sending the Ajax request. 该代码在发送Ajax请求之前一直有效。

$('#stream').infinitescroll({
    navSelector     : ".paginate:last",
    nextSelector    : "a.paginate:last",
    dataType    : 'json',
    appendCallback  : false,
    path: function(path,page){
     return $("a.paginate:last").attr("href");
    }
}, function(json, opts){

});

But I have to set request header in the Ajax call for authentication in the server side. 但是我必须在Ajax调用中设置请求标头以在服务器端进行身份验证。

How to pass request headers with the url. 如何通过网址传递请求标头。

Thanks, 谢谢,
Srikanth 斯里坎特

Right now there is no solution via Infinite Scroll , 现在没有通过无限滚动的解决方案,

One solution that worked is, Adding the headers to global ajax handler. 一种有效的解决方案是,将标头添加到全局ajax处理程序。

$.ajaxSetup({
  beforeSend: setHeader
});

var setHeader = function (xhr) {
  xhr.setRequestHeader('Header1', 'XXX');
  xhr.setRequestHeader('Header2', 'YYY');
}

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM