大家好!
我已将pjax集成到我的网站。它正在运行,但其他js脚本,如GoogleMap或DataTable - 没有。如果按f5重新加载页面 - 页面上的所有其他js工作完美!我做错了什么?如何解决这个问题?
答案 0 :(得分:2)
Pjax使用ajax替换内容,因此您可能只是在文档上加载javascript,并且需要在pjax完成时重新加载它。有一个处理程序,你可以在完成pjax时使用它来重启你的javascript。
您可以在https://github.com/defunkt/jquery-pjax
的github页面上查看pjax的事件滚动到底部查看活动。
但你可能会做类似下面的事情,但很难说你没有发布任何代码。
您可以声明您的功能,然后在文档就绪时启动它们,并在pjax完成之后启动它们。
function datatables(){
//your datatables code here
{
function googleMaps(){
//your google maps code here
}
$( document ).ready(function() {
datatables();
googleMaps();
});
$(document).on('pjax:complete', function() {
datatables();
googleMaps();
});
或者您可以在文档准备就绪以及pjax如此完成时说明它们
$( document ).ready(function() {
//your datatables code here
//your google maps code here
});
$(document).on('pjax:complete', function() {
//your datatables code here
//your google maps code here
});
或者那种效果。
希望它有所帮助。