![](/img/trans.png)
[英]Why can't I get my android emulator to connect to my local server?
[英]Can i connect to a local .json file on my server and template it?
我在kasserver.com上有一个网络服务器,我使用 PHP 脚本每 15 分钟获取一个 API 并将其保存在我的网络服务器上。 现在我想对保存的 JSON 数据进行模板化,但我可以在本地访问它。
handleEvents('test, "./json/tester.json");
function handleEvents(id, link) {
fetch(link).then(res => {
res.json().then(
t => {
if (t.length > 0) {
let output = "";
for(let i=0, len = t.length; i < len; i++) {
output = data[i].person;
}
document.getElementById(id).innerHTML = output;
} else {
document.getElementById(id).innerHTML = "<div>Aktuell sind noch keine genaueren Details verfügbar</div>";
}
}
)});
}
但它尝试获取本地 URL,而不是使用来自 Web 服务器的数据。 我还找不到如何在我的服务器上获取本地 JSON 文件的方法。
您无法通过客户端访问服务器的本地位置。 如果您的文件位于 PHP 服务器的公共区域,您可以通过带域的完整 URL 访问它
function handleEvents(id, link) {
fetch(`https://${location.hostname}${link}`)
.then(res => {
// ...
// ...
}
}
handleEvents('test', '/json/tester.json')
所以,你必须像这样编写函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.