api - 将数据从 api 传递到 html 文件
问题描述
所以我使用openweather api来获取天气数据,我想将数据发送到一个html文件或者一个嵌入html的js文件中,但我不知道我该怎么做。这是我到目前为止得到的代码
app.get("/",function(req,res){
const url="https://api.openweathermap.org/data/2.5/weather?q=Toronto &appid=apikey&units=metric";
https.get(url,function(response){
response.on("data",function(data){
const weatherData=JSON.parse(data);
var temp=weatherData.main.temp;
var describtion=weatherData.weather[0].description;
var icon=weatherData.weather[0].icon;
var imgURL="http://openweathermap.org/img/wn/"+icon+"@2x.png";
res.write("<p>The weather is "+ describtion + "</p>");
res.write("<h1>The temperature in " +"Toronto is "+ temp + " celcius</h1>");
res.write("<img src="+imgURL+">");
});
res.sendFile(__dirname+"/index.html");
});
});
我想传递临时、描述和 img url,并在用户发送 get 请求时显示在 html 中,默认情况下它显示多伦多的天气而没有发布请求。谢谢!!!
解决方案
推荐阅读
- ruby - CSV.foreach 未读取 CSV 文件中的第一列
- javascript - Brightcove:转到视频中的特定时间
- hyperledger-fabric - 未安装 Docker 并通过下载 Fabric 图像
- r - Ifelse...在这里使用正确的功能吗?
- r - 取消合并 ggplot 图例
- amazon-web-services - Quicksight 没有显示没有数据的月份(null?)
- c# - Oxyplot 跟踪器在 Xamarin.Forms 中不起作用
- django - Django Heroku:python:无法打开文件'manage.py':[Errno 2]没有这样的文件或目录
- image-processing - 计算 FIJI/ImageJ 中不同颜色的点之间的距离
- c# - 如何在后台运行 c# 控制台应用程序 .exe?