javascript - 在 JavaScript 中获取两个 URL(在点击监听器内)
问题描述
我想使用这两个 API,但第二个不起作用。这两个实际上是在一个点击监听器中。
fetch('https://api.openweathermap.org/data/2.5/weather?lat=' + coord.lat + `&lon=` + coord.lng + '&units=metric&appid=xxx')
.then(response => response.json())
.then(data => {
var tempValue = data['main']['temp'];
var descValue = data['weather'][0]['main'];
temp.innerHTML = "Temp: " + tempValue;
desc.innerHTML = "Desc: " + descValue;
//jamFactor.innerHTML = "Traffic jam: "
})
fetch('https://traffic.ls.hereapi.com/traffic/6.2/flow.json?apiKey=xxx&prox=39.8485715,-86.0969867,10')
.then(response => response.json())
.then(data => {
var jfValue = data['RWS'][0]['RW'][0]['FIS'][0]['FI'][0]['CF'][0]['JF'];
jamFactor.innerHTML = "Traffic jam: " + jfValue;
})
解决方案
推荐阅读
- javascript - jQuery FormBuilder 仅验证必填字段
- python - 如何在robot.api中调用监听类?
- python - 不允许我在函数和 int 之间使用 >
- java - How do you remove an element from an array based on element's field value? (Spring-Boot, Reactive MongoDB)
- python - 覆盖 Flask Admin 在表中保存新行
- python-3.x - 我在尾部函数中的插入节点不会改变尾部的值
- firebase - 无法在 Firebase 中创建用户配置文件
- javascript - Javascript - Making an object and incrementing count in an array for each loop
- r - ggplot2 theme to color inside of polar plot
- c# - Unity:将 json 字符串反序列化为 C# 对象