The question is: How do I display this res.json() in a HTML page. I don’t want to show something like { _id: dfjkdsfj, blah: fdksfj, blah: blahblah } on the newly directed page:
If you’re returning JSON data, it can’t be read in html other than as text, you will need JavaScript.
If you’ve already got a page that displays raw json, you can use ajax to make a request to that url and obtain the JSON, then process it into the document you want to display.
Have you got any code you can show? I’m not really sure what’s going with your application so all my comments are just guesses based on the second picture.
My code is a terrible mess right now because I have been trying so many different stuff.
Here is the work flow of my code:
A form.
Submit button
Links to a different page (ex: /detail?name=blah?id=blah
Using name and id, call to an API fetch to get the information I want.
/detail?name=blah?id=blah now outputs a res.json page (like the one shown in the first picture).
I want to convert that res.json page into the HTML one.
Do you have a video I can look at that does that thing you said? Most of the ones I could find already have the json object available. Those don’t really help because they don’t consider that I have to fetch the information from another API first.
Here, I cleaned up my code to make it readable:
I am not sure if it will work for you, but you can try typing in like “Urgot” for the first box, and then like “Doublelift” for the second box. You will see a res.json page.
My idea was to use an Ajax request to get the data and then parse it on the screen.
To do this, first point the form to another page that returns detailpg.html page and change the server code to fulfil the JSON request at /api/detail.
In detailpg,html, add some javascript that reads the url parameters (location.pathname) , adds /api/ and use fetch to request the JSON.