[Progress Communities] [Progress OpenEdge ABL] Forum Post: Basic consumption of rest response by simple javascript

Status
Not open for further replies.
O

OctavioOlguin

Guest
I'm following this demo How to Connect to an API with JavaScript to learn about publishing and consuming services (rest) from PASOE. I got struck at the part about: const app = document.getElementById('root'); const logo = document.createElement('img'); logo.src = 'logo.png'; const container = document.createElement('div'); container.setAttribute('class', 'container'); app.appendChild(logo); app.appendChild(container); var request = new XMLHttpRequest(); //request.open('GET', ' ghibliapi.herokuapp.com/films' , true); request.open('GET', ' 200.77.145.150:8818/.../Precios' , true); request.onload = function () { // Begin accessing JSON data here /*var data = JSON.parse(this.response); if (request.status >= 200 && request.status { const card = document.createElement('div'); card.setAttribute('class', 'card'); const h1 = document.createElement('h1'); h1.textContent = precio.Articulo; const p = document.createElement('p'); precio.Nombre = precio.Nombre.substring(0, 300); p.textContent = `${precio.Nombre}...`; container.appendChild(card); card.appendChild(h1); card.appendChild(p); }); } else { const errorMessage = document.createElement('marquee'); errorMessage.textContent = `Gah, it's not working!`; app.appendChild(errorMessage); }*/ var data = JSON.parse(this.response) data.forEach(movie => { // Log each movie's title console.log(movie) }) } But I think that is not working (it throws: transp1.js:44 Uncaught TypeError: data.forEach is not a function at XMLHttpRequest.request.onload (transp1.js:44) because the extra outer objects that are part of response: { "response":{ "ttPrecios":{ "ttPrecios":[ { "Articulo":"ADOBADO", "Nombre":"ADOBADO", "Menudeo":58.0, "Mayoreo":53.0, "SoloMayoreo":0 }, { "Articulo":"AGUJA Res", "Nombre":"AGUJA Res", "Menudeo":80.0, "Mayoreo":76.0, "SoloMayoreo":0 } ] } } } Where should I look at handbook, in order to learn this techniques? Thanks Jorge

Continue reading...
 
Status
Not open for further replies.
Top