首页 > 关于pjax中的局部刷新,整个页面刷新会跳转页面的问题

关于pjax中的局部刷新,整个页面刷新会跳转页面的问题

pjax中的局部刷新中,改变了地址栏中的url改变了,当整个页面刷新时,整个页面跳转了,有没有什么好的解决办法,求具体代码?


可能是pjax获取数据超时导致的默认行为:直接访问a标签。Pjax::begin(['id' => 'admin-crud-id', 'timeout' => false]);这样不设置超时,或者给个比较大的值应该可以解决问题。


你没有拦截页面的默认事件, 例如点击 <a><button> 时, 执行 pjax 的同时,浏览器跳转了。
在你程序第一行,首先应该 event.preventDefault(), 用法自己搜;
然后再写 history 和 ajax 的逻辑。


<?php Pjax::begin(
    [
        'enablePushState' => false,
        'timeout'         => 10000,
    ]
); ?>

timeout要设置长一些。

/**
     * @var integer pjax timeout setting (in milliseconds). This timeout is used when making AJAX requests.
     * Use a bigger number if your server is slow. If the server does not respond within the timeout,
     * a full page load will be triggered.
     */
【热门文章】
【热门文章】