httprequest.js 683B

123456789101112131415161718192021
  1. let httpRequest = new XMLHttpRequest();
  2. httpRequest.open("GET", "https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD", true);
  3. httpRequest.onreadystatechange = function () {
  4. if ((httpRequest.readyState === 4) && (httpRequest.status === 200)) {
  5. let jsonData = JSON.parse(httpRequest.responseText).data;
  6. for (let i = 0; i < jsonData.length; i++) {
  7. if (jsonData[i][10] === "Golden Gate Bridge") {
  8. document.getElementById('result').innerHTML += (jsonData[i][8] + " (" + jsonData[i][9] + ")<br>Produced by "
  9. + jsonData[i][12] + "<br><br>");
  10. }
  11. }
  12. }
  13. };
  14. httpRequest.send();