提问人:Rushil Gupta 提问时间:11/15/2023 最后编辑:Rushil Gupta 更新时间:11/16/2023 访问量:42
为什么 client-js 显示来自 API 的数据不起作用?
why does client-js to display data from a api doesn't work?
问:
整个代码 该代码应该显示 /constants 目录中所有文件的名称,但随后它应该显示不起作用的文件的值 我尝试了大约 4 小时甚至更长时间的故障排除
我对错误部分的看法
document.addEventListener('DOMContentLoaded', function () {
const constantLinks = document.querySelectorAll('.lst');
const constantValue = document.getElementById('constantValue');
constantLinks.forEach(link =>
link.addEventListener('click', function (event) {
event.preventDefault();
fetch('https://localhost:3000/data/' + this.textContent.split('(')[0])
.then(response => response.text())
.then(value => {
constantValue.textContent = value;
})
.catch(error => {
console.error('Error:' + error);
});
}
)
)
});
我所期望的网站是一种不同的、更慢的方式来用 PHP 做同样的事情,我正在尝试用 node 替换它 我尝试使用console.logs,但它不起作用
答:
0赞
Dean Van Greunen
11/16/2023
#1
尝试禁用证书检查,因为它不是有效的签名证书
const https = require('https');
fetch('https://localhost:3000/data/' + this.textContent.split('(')[0], {
agent
})
.then(response => response.text())
.then(value => {
constantValue.textContent = value;
})
.catch(error => {
console.error('Error:' + error);
});
评论
1赞
Rushil Gupta
11/16/2023
这是行不通的,但是在GitHub上有一种混乱的方式可以工作
1赞
Rushil Gupta
11/16/2023
如果你能帮忙清理,我将不胜感激。我认为这不是正确的方式
0赞
Dean Van Greunen
11/16/2023
@RushilGupta或者您可以在计算机上安装证书,那么您将不需要对 SSL 进行这种笨拙的禁用
评论
https://localhost:3000/data/
http://localhost:3000/data/