简体   繁体   中英

view json api from url into an html page by js

how to parse json from an url into html by using javascript (programmatically) and i facing an problem with this?

api: https://corona.ps/API/summary

You need to use the built in JavaScript fetch() method which returns a promise. Use.then() to handle the response and.catch() to handle any errors relating to the fetch call.

Here's an example function using your api link:

function getData () {
    fetch("https://corona.ps/API/summary")
     .then(res => res.json())
     .then(data => console.log(data)) // will log js object
     .catch(err => console.log(err))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM