Odd TypeError being thrown.
-
Working on a website in Node.JS, and I've been doing good so far, but I've hit an error that has me stumped.
TypeError: Cannot set property 'isSubmitted' of undefined
at app.post.res.locals.showform (/media/sf_Node.js/SmartCage2/user.js:76:25)
at Layer.handle [as handle_request] (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/layer.js:95:5)
at next (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/layer.js:95:5)
at /media/sf_Node.js/SmartCage2/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/index.js:330:12)
at next (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/index.js:271:10)
at jsonParser (/media/sf_Node.js/SmartCage2/node_modules/body-parser/lib/types/json.js:100:40)
at Layer.handle [as handle_request] (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/layer.js:95:5)The section that's throwing the error:
app.get('/login', function (res, req) {
res.locals.isSubmitted = false;
res.render("user/login.html");
});The odd thing is, I use the same code above this, and it works.
app.get('/register', function(req,res) {
res.locals.isPosted = false;
res.render("user/register.html");
});I have the forms submitted to the corresponding page (/login to /login, /register to /register), and I use the Nunjucks template system to show relevant data depending on how whether it was accessed via GET or POST. I have no idea why it would be throwing the error on one section, but not the other. I do, however, want to note that I barely know Javascript. I've always used strongly typed languages. I don't even like using 'var' in C#.
-
Working on a website in Node.JS, and I've been doing good so far, but I've hit an error that has me stumped.
TypeError: Cannot set property 'isSubmitted' of undefined
at app.post.res.locals.showform (/media/sf_Node.js/SmartCage2/user.js:76:25)
at Layer.handle [as handle_request] (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/layer.js:95:5)
at next (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/layer.js:95:5)
at /media/sf_Node.js/SmartCage2/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/index.js:330:12)
at next (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/index.js:271:10)
at jsonParser (/media/sf_Node.js/SmartCage2/node_modules/body-parser/lib/types/json.js:100:40)
at Layer.handle [as handle_request] (/media/sf_Node.js/SmartCage2/node_modules/express/lib/router/layer.js:95:5)The section that's throwing the error:
app.get('/login', function (res, req) {
res.locals.isSubmitted = false;
res.render("user/login.html");
});The odd thing is, I use the same code above this, and it works.
app.get('/register', function(req,res) {
res.locals.isPosted = false;
res.render("user/register.html");
});I have the forms submitted to the corresponding page (/login to /login, /register to /register), and I use the Nunjucks template system to show relevant data depending on how whether it was accessed via GET or POST. I have no idea why it would be throwing the error on one section, but not the other. I do, however, want to note that I barely know Javascript. I've always used strongly typed languages. I don't even like using 'var' in C#.
-
Vouksh wrote:
I barely know Javascript
Nor me, but the implication of that message is that your
res
object has not been initialised correctly. -
Wow, I feel like an idiot. I glanced back over my code... and I had the 'req' and 'res' vars reversed. :doh: But I likely wouldn't have noticed if you didn't point out something with the variables.
-
Vouksh wrote:
I feel like an idiot.
Something we have all had to admit from time to time.
me to, hahahaah west bengal voter list