script
tag in the HTML response. The script
tag's src
attribute triggers a GET request.script
tag, the file contents in the response is digested by the JavaScript interpreter of the browser./ha
./ha
. The server sends back a JSON response.createdb
with the DB name in config/config.jshttp://localhost:3004/items
in the browser to verify the server is set up and the browser can receive items in the response.script
tag to the view page for a JavaScript file called script.js
script
tag to the view page to import Axios.script.js
to the public
folder.console.log
on line 6. Our starter code is sending back data from the server here: https://github.com/rocketacademy/ajax-bootcamp/blob/main/controllers/items.mjs#L5 When the browser gets to line 6 we have access to the data sent back from the server.console.log
on line 6 in script.js
outputs a JavaScript object. This is the final step, step 8. The Axios library has transformed the string HTTP GET request response into a JavaScript object. To explicitly demonstrate that this is a live object, console.log
only the name of the first item in the response.script.js
, manipulate the DOM to show all items in the HTML page.script.js
such that the above AJAX request and DOM manipulation happens when we click the button.