[英]Multiple get request using axios in Nodejs
I want to send two API data to the HTML file using Axios But I can not figure out the problem please help me with that My code is我想使用 Axios 将两个 API 数据发送到 HTML 文件但我无法弄清楚问题请帮帮我 我的代码是
app.get('/', (req, res) => {
const Url1 = "https://api.covidindiatracker.com/state_data.json";
const x = axios.get(Url1).then((response1) => {
res.render("index", {
appName: "COVID-19 Tracker",
pageName: "India Fights Corona",
data1: response1.data
});
})
});
app.get('/', (req, res) => {
const Url2 = "https://api.covidindiatracker.com/total.json";
const y = axios.get(Url2).then((response2) => {
res.render("index", {
data2: response2.data
});
})
});
in my HTML page在我的 HTML 页面中
<h3><%= JSON.stringify(data1.recovered) %></h3>
and
<td><%= data2.id %></td>
Why it not work please help me为什么它不起作用请帮助我
app.get('/', (req, res) => {
const url1 = "https://api.covidindiatracker.com/state_data.json";
const Url2 = "https://api.covidindiatracker.com/total.json";
axios.all([
axios.get(url1),
axios.get(url2)
]).then(axios.spread((data1, data2) => {
res.render("index", appName: "COVID-19 Tracker",
pageName: "India Fights Corona",
data1: data1.data,
data2: data2.data
}));
});
This Link will be helpful这个链接会有帮助
How to post multiple Axios requests at the same time? 如何同时发布多个 Axios 请求?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.