功能
<script th:inline="javascript" th:if="${theme.config.basic.enable_pjax}">
var apiRequested = false;
$(document).pjax('a[data-pjax]', '#data-pjax', {
timeout: 5000,
fragment: '#data-pjax',
scrollTo: false
});
$(document).on('pjax:start', function () {
$('#joe_index__article');
});
$(document).on('pjax:end', function () {
$('#joe_index__article');
$('html, body').animate({ scrollTop: 0 }, 500);
refreshBusuanziScript();
if (!apiRequest) {
refreshBusuanziAPI();
apiRequest = true;
}
});
function refreshBusuanziScript() {
$('script[src="/js"]').remove();
var script = document.createElement('script');
script.src = '/js';
script.type = 'text/javascript';
document.body.appendChild(script);
}
function refreshBusuanziAPI() {
$.ajax({
url: '/api',
type: 'GET',
});
}
</script>
流程
if (!apiRequest) {
refreshBusuanziAPI();
apiRequest = true;
}
报错
Uncaught ReferenceError: apiRequest is not defined
at HTMLDocument.<anonymous> ((索引):2594:13)
at HTMLDocument.dispatch (jquery.min.js:2:43090)
at v.handle (jquery.min.js:2:41074)
at Object.trigger (jquery.min.js:2:71513)
at HTMLDivElement.<anonymous> (jquery.min.js:2:72108)
at Function.each (jquery.min.js:2:2976)
at S.fn.init.each (jquery.min.js:2:1454)
at S.fn.init.trigger (jquery.min.js:2:72084)
at m (jquery.pjax.min.js:1:1582)
at d.complete (jquery.pjax.min.js:1:2141)
后文
定义apiRequest后api会重复请求,不定义apiRequest控制台会报错,但api不会重复请求。
我如何对待你都有错,该放弃你吗?
后记
NND,放头部就行了,放在重要位置才行……
评论区