Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get POST data #9

Open
dieka2501 opened this issue Jul 29, 2015 · 0 comments
Open

Cannot get POST data #9

dieka2501 opened this issue Jul 29, 2015 · 0 comments

Comments

@dieka2501
Copy link

hello Mr Han and Mr Jollen, how are you?

i want to ask something, how to get the post data? I try post data but it always show error

TypeError: Cannot read property 'user' of undefined at Object.handle (/home/dikdik/nodeapp/router/main.js:11:26) at next_layer (/home/dikdik/nodeapp/node_modules/express/lib/router/route.js:103:13) at Route.dispatch (/home/dikdik/nodeapp/node_modules/express/lib/router/route.js:107:5) at c (/home/dikdik/nodeapp/node_modules/express/lib/router/index.js:195:24) at Function.proto.process_params (/home/dikdik/nodeapp/node_modules/express/lib/router/index.js:251:12) at next (/home/dikdik/nodeapp/node_modules/express/lib/router/index.js:189:19) at next (/home/dikdik/nodeapp/node_modules/express/lib/router/index.js:166:38) at Layer.expressInit as handle at trim_prefix (/home/dikdik/nodeapp/node_modules/express/lib/router/index.js:226:17) at c (/home/dikdik/nodeapp/node_modules/express/lib/router/index.js:198:9)

i try googling it, but still didn't get any result.
this is my source code.

//server.js
var express=require('express');
var bodyParser = require('body-parser');
var http = require('http');
var app=express();

require('./router/main')(app);
app.set('views',__dirname+'/views');
app.set('view engine','ejs');
app.engine('html',require('ejs').renderFile);
app.use(bodyParser.text());
app.use(bodyParser.urlencoded({extended:true}));
var server=app.listen(3000,function(){
console.log("Started listen port 3000");
});

//main.js
module.exports=function(app){

app.get('/',function(req,res){
    var body = '';
    var url  = "http://localhost:3000/";
    res.render('index.html',{title:'Apa atuh',content:'Ini content',url:url});
});
app.post('/about',function(req,res){
    var username = req.body.user;
    var password = req.body.pass;
    res.render('about.html',{user:username,pass:password});
});

}

i start to learn again nodejs, but i already forget about it, can you help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant