zhheo/Post-Abstract-AI

主题有pjax加载,跨域问题

planet-cx330 opened this issue · 2 comments

你好,开发者,我自己用的Typecho博客主题
按照文档成功添加上了,可是发现一个问题:
从首页点进文章,是无法正常显示这个Ai文章摘要的
必须重新按F5刷新或者直接输入网址进入,才显示Ai文章摘要

通过F12报错显示:
aigpt.js:149 Uncaught (in promise) TypeError: Cannot set properties of null (setting 'innerHTML')
at aigpt.js:149:32

对应的函数如下:
tianliGPT.fetchTianliGPT(content).then(summary => {
const aiExplanationDiv = document.querySelector('.tianliGPT-explanation');
aiExplanationDiv.innerHTML = summary;
})
}

zhheo commented

pjax需要进行单独的适配,如果你的主题没有单独的pjax标签做适配,那么需要自定义js函数。将tianligpt最后一行的

checkURLAndRun()

改为

document.addEventListener('pjax:complete', function () {
checkURLAndRun()
}

即可

之前能用,最近一直报跨域问题403用不了了咋整?