javascript - How to properly fetch data from iTunes API? -


so i'm trying use vanilla javascript , fetch itunes' api create page allows user type in artist name , compile page 15 top results. i'm using following fetch:

 function datapull() {   fetch("https://itunes.apple.com/search?term=")   .then(function(response) {       if (response.status !== 200) {         console.log(response.status);         return;       }       response.json().then(function(data){         console.log(data);         let returnresponse = document.createelement("div");         let input2 = inputelement.value;         (let i=0; i<data.length; i++){           if (inputelement===data[i].artistname){             console.log(data[i].artistname);             returnresponse.innerhtml = `             <div class="box">             <img src=${artworkurl30} alt="album image">             <p><span>artist name:</span>${data[i].artistname}</p>             <p><span>track: </span>${data[i].trackname}</p>             <p><span>album name: </span>${data[i].collectionname}</p>             <p><span>album price: </span>${data[i].collectionprice</p>             </div>             `;             results.appendchild(returnresponse);         }}         console.log(data);       });     }   ) 

the function being called in click event , i'm sure can put "let returnresponse" down append in function. issue i'm having getting api show results. @ moment if type in bruno mars, beethoven, or u2 it's not logging data , it's giving me "provisional headers shown" when check out the status code.

any thoughts on make better/work?

for full code: jsfiddle

typical fetch call this.

fetch(`${url}`)     .then(response => response.json())     .then(json =>       // json     ) 

modify code , see if can console.log() of note.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -