How to run jQuery before and after a pjax load?

只谈情不闲聊 提交于 2019-12-03 07:59:44

As they says in their doc here pjax fires two events for what you need

pjax will fire two events on the container you've asked it to load your reponse body into:

pjax:start - Fired when a pjax ajax request begins.

pjax:end - Fired when a pjax ajax request ends.

And the code example for this

$('a.pjax').pjax('#main')
$('#main')
  .on('pjax:start', function() { //do what you want to do before start })
  .on('pjax:end',   function() { //after the request ends });
Raab
$("body").on("click", "a", function(){

 $(this).pjax("#main");
 $('a.pjax').pjax('#main')
 $('#main').on('pjax:start', function() { /* your code before ajax load */ });
 $('#main').on('pjax:end',   function() { /* your code after ajax load */ });

  return false;
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!