best way to implement an overlay with pjax

[亡魂溺海] 提交于 2019-12-04 18:30:59

Try to make it a simple PJAX request with beforeSend and complete attributes.

The beforeSend attribute will be executed before the http request is fired. I use it often when making a loader for a certain AJAX/PJAX event. Whenever the user fires the event (i.e. clicks a button), the function, assigned to beforeSend, hides the content of the div that I am updating and places a gif loader there, which gives a nice user experience.

The complete attribute will be executed after the requested page loads. If I use the example I gave with the loader, you can make the function, assigned to the complete attribute, hide the loader image and update the div with the loaded content from the requested page.

Here is an example with the loader image:

$.pjax({
    url: 'requested_page.php',
    container: '#updated_div',
    beforeSend: function(){
        $('#loader_place').fadeIn('normal'); // This will fade in a hidden div with fixed centered position
    },
    complete: function(){
        $('#loader_place').fadeOut('normal'); // This will fade out the div and make it invisible again
    }
});

If you want to do something more complicated, I suggest you read the PJAX Documentation.

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