{"id":72597,"date":"2026-05-04T03:01:00","date_gmt":"2026-05-03T17:01:00","guid":{"rendered":"https:\/\/www.rjmprogramming.com.au\/ITblog\/?p=72597"},"modified":"2026-05-03T18:31:40","modified_gmt":"2026-05-03T08:31:40","slug":"javascript-fetch-api-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-fetch-api-primer-tutorial\/","title":{"rendered":"Javascript Fetch API Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/fetch_api.gif\" rel=\"noopener\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Javascript Fetch API Primer Tutorial\" src=\"\/fetch_api.gif\" title=\"Javascript Fetch API Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Javascript Fetch API Primer Tutorial<\/p><\/div>\n<p>More and more, around here, recently, constructing web applications using PHP\/HTML\/Javascript we have added to a list of &#8220;URL response tools&#8221;, adding to an &#8220;off the top of our head&#8221; list of (just the HTML and Javascript &#8220;client side&#8221;) navigational ideas &#8230;<\/p>\n<ul>\n<li>location.href='[URL]&#8217;; #same webpage, but reload, perhaps with different content<\/li>\n<li>document.location.reload(); #same webpage, same initial content, cache may come into play<\/li>\n<li>Refresh (eg. every 5 seconds) via head element subelement like &lt;meta http-equiv=&#8221;refresh&#8221; content=&#8221;5&#8243;&gt;  #same webpage, same initial content, cache may come into play<\/li>\n<li>window.open(&#8216;[URL]&#8217;,&#8217;_blank&#8217;); #new webpage<\/li>\n<li>window.open(&#8216;[URL]&#8217;,&#8217;_self&#8217;); #same webpage, perhaps with different content<\/li>\n<li>HTML form action='[URL]&#8217; target=_blank #new webpage<\/li>\n<li>HTML form action='[URL]&#8217; target=_self  #same webpage, but reload, perhaps with different content<\/li>\n<li>location.hash=&#8217;#[stuff]&#8217;; #same webpage, no reload, detect, analyze and act on [stuff]<\/li>\n<li>location.href=&#8217;#[stuff]&#8217;; #same webpage, no reload, detect, analyze and act on [stuff]<\/li>\n<li>Ajax open then send([perhaps FormData object]);  #same webpage, extract content &#8230; we&#8217;ve recently started using another way to extract information but stay on the same webpage as &#8230;<\/li>\n<li><a target=\"_blank\" title='Fetch API information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/api_fetch.asp' rel=\"noopener\">Fetch API Javascript<\/a> &#8220;fetch&#8221; command   #same webpage, extract content<\/li>\n<\/ul>\n<p> &#8230; we&#8217;ve used to, so far &#8230;<\/p>\n<ul>\n<li>derive &#8220;one run through&#8221; duration of Animated GIF URL in var<sip>iable<\/sup> <a target=\"_blank\" title='fetch(whatgifmaybe' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/?s=fetch%28whatgifmaybe&#038;stype=Search' rel=\"noopener\">&#8220;whatgifmaybe&#8221;<\/a> &#8230;<br \/>\n<code><br \/>\nfetch(whatgifmaybe.replace('http:','').replace('https:',''))<br \/>\n  .then(res => res.arrayBuffer())<br \/>\n  .then(ab => isGifAnimated(new Uint8Array(ab)))<br \/>\n  .then(console.log);<br \/>\n}<br \/>\n<\/code><\/li>\n<li>derive content of URL (<a target=\"_blank\" title='const res = await fetch(' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/?s=const+res+%3D+await+fetch%28&#038;stype=Search' rel=\"noopener\">which returns JSON array list of image URLs<\/a>) &#8230;<br \/>\n<code><br \/>\n\/\/ Thanks to <a target=\"_blank\" title='const res = await fetch(' rel=\"noopener\"><br \/>\n  const res = await fetch(\".\/index.php?diris=images&prefixis=DSC_0&startsuffix=279&endsuffix=364\", {\/* options here *\/});<br \/>\n  const data = await res.json();<br \/>\n<br \/>\n  for (var inm=0; inm&t;data.length; inm++) {<br \/>\n    image_list[image_index++] = new imageItem(data[inm]);<br \/>\n    console.log('Added ' + data[inm]);<br \/>\n  }<br \/>\n<br \/>\n  console.log(data);<br \/>\n  console.log(\"Some code after that uses data\");<br \/>\n<br \/>\n})();<br \/>\n<\/code><\/li>\n<\/ul>\n<p> &#8230; but who knows what the future brings?!<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d72597' onclick='var dv=document.getElementById(\"d72597\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/navigation\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d72597' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>More and more, around here, recently, constructing web applications using PHP\/HTML\/Javascript we have added to a list of &#8220;URL response tools&#8221;, adding to an &#8220;off the top of our head&#8221; list of (just the HTML and Javascript &#8220;client side&#8221;) navigational &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-fetch-api-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[88,212,4286,233,5465,576,830,997,1997,2124,1319,1345],"class_list":["post-72597","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-api","tag-client","tag-clientside","tag-command","tag-fetch-fetch-api-javascript","tag-html","tag-navigation","tag-programming","tag-request","tag-response","tag-tutorial","tag-url"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/72597"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=72597"}],"version-history":[{"count":14,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/72597\/revisions"}],"predecessor-version":[{"id":72612,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/72597\/revisions\/72612"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=72597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=72597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=72597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}