load data from a url
- Fetch JSON data from a URL with
b.getData(url).
- If there's an error in the fetch or the parsing an error is logged
to the console and
undefined is returned.
html
<div data-r="init"></div>
javascript
export const b = { init: "init" };
const url = `/versions/8/0/0/snippets/get-remote-data/data.json`;
export async function init(_, __, el) {
const data = await b.getData(url);
if (data) {
el.innerHTML = data.status;
} else {
el.innerHTML = "could not load data";
}
}
data.json
{
"status": "remote data loaded"
}