您好,我正在尝试用 .txt 文件中的文本填充 html 段落,以便能够从文本文件中编辑该段落,而不是在代码上进行编辑,我在运行使用 VS Code 实时服务器的网站呈现完美,但是当我使用 vercel 部署网站时,文本没有显示,并且在开发工具中显示“无法加载资源:服务器响应状态为 404 () text/intro-p1.txt :1"。我不知道为什么它适用于实时服务器,而不是在我部署页面时。
//JS Code
function ajax(method, url, data, success, error) {
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.setRequestHeader("Accept", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState !== XMLHttpRequest.DONE) return;
if (xhr.status === 200) {
success(xhr.response, xhr.responseType);
} else {
error(xhr.status, xhr.response, xhr.responseType);
}
};
xhr.send(data);
}
//load text function
jQuery.get('text/intro-p1.txt', function(data) {
//First paragraph of main page introduction
$('#intro-p1').html(data.replace('n',''));
});
jQuery.get('text/intro-p2.txt', function(data) {
//Second paragraph of main page introduction
$('#intro-p2').html(data.replace('n',''));
});
//P.S I also tried changing 'text/intro-p2.txt' to '/text/intro-p2.txt'
//To see if the path was incorrect but had no result there
<!-- HTML code -->
<section id="about">
<div class="container-fluid">
<h1 class="big-heading"><i>ACCURATE SOLUTIONS CORP.</i></h1>
<p id="intro-p1" class="company-description"></p>
<p id="intro-p2" class="company-description"></p>
</div>
</section>
项目文件层次结构
感谢您提供的任何帮助!