Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSean Gibson
38,363 PointsBrowser Refresh triggers both GET & POST??
I am trying to follow along in Express Basics => Deeper Into Routing with Express => The Request Object but noticing what seems strange;
The body is being returned to the console both when I click the Submit button AND when I simply refresh the browser. Is this not unusual? I would have thought that GET and POST were clearly separated. Does the mere presence of a submit button trigger a POST request? Am I perhaps just not far enough into the video/topic? Specifically, I am o at the 03:30ish mark of the video.
I am using the following in my app.js file:
app.get("/hello", (req, res)=>{ res.render("hello"); });
app.post("/hello", (req, res)=>{ console.dir(req.body); => showing 'undefined' as expected but also upon browser refresh res.render("hello"); });
1 Answer
Sean Gibson
38,363 PointsOK, so I think I worked out what's going on, so thought I'd (at lease partially) answer my own question here in case anyone else had the same concern.
In short: Yes, I was not yet far enough into the lesson. Andrew later explains this behavior in the next video, The Response Object', at the 04:18 mark.
It seems that info (variables, last submissions) is retained even when simply refreshing the browser. To clear it, you need to reenter the URL (or simply click in the address bar and hit enter). Otherwise the browser still remembers everything you've done.
If someone more knowledgeable than me has anything to add/correct please let us know.