Difference between revisions of "DOM working with data"
Jump to navigation
Jump to search
(Created page with "<pre id='shellbody' data-qtp='DOM'></pre> <div class=qu> <pre class=usr> </pre> <pre class=ans> </pre> </div>") |
|||
Line 1: | Line 1: | ||
<pre id='shellbody' data-qtp='DOM'></pre> | <pre id='shellbody' data-qtp='DOM'></pre> | ||
*You can obtain data form the server using a fetch call. | |||
*In these examples you will be getting data from /worldl.json this is a list of 195 countries in json format | |||
<div class=qu> | <div class=qu> | ||
* The program snippet shows the name of country 42. | |||
* Change it so it shows the name of country 50. | |||
<pre class=usr> | <pre class=usr> | ||
fetch('/worldl.json') | |||
.then(r=>r.json()) | |||
.then(r=>{ | |||
let tgt = r[42]; | |||
document.body.innerHTML = tgt.name; | |||
}); | |||
</pre> | </pre> | ||
<pre class=ans> | <pre class=ans> | ||
fetch('/worldl.json') | |||
.then(r=>r.json()) | |||
.then(r=>{ | |||
let tgt = r[50]; | |||
document.body.innerHTML = tgt.name; | |||
}); | |||
</pre> | </pre> | ||
</div> | </div> |
Revision as of 16:24, 21 August 2021
- You can obtain data form the server using a fetch call.
- In these examples you will be getting data from /worldl.json this is a list of 195 countries in json format
- The program snippet shows the name of country 42.
- Change it so it shows the name of country 50.
fetch('/worldl.json') .then(r=>r.json()) .then(r=>{ let tgt = r[42]; document.body.innerHTML = tgt.name; });
fetch('/worldl.json') .then(r=>r.json()) .then(r=>{ let tgt = r[50]; document.body.innerHTML = tgt.name; });