I just started working in node js for last few days. On an onclick ,I am calling this function which has an ajax call here.
function goToUser(){
$.ajax({
url:"/users/UserPage",
type:'get',
async:false,
success:function(data){
alert("working")
}
})
}
In the users.js I have given like this
var express = require('express');
var router = express.Router();
router.get('/UserPage',function(req,res){
res.render("/users/UserPage");
})
in the UserPage.jade file, it is like this
h3#getHeader Helooooo
But its not working is there any mistake in this? What I just want to redirect to another jade page, I used both render and redirect here.But both are not working.
My Package .json dependencies
"dependencies": {
"express": "~4.2.0",
"static-favicon": "~1.0.0",
"morgan": "~1.0.0",
"cookie-parser": "~1.0.1",
"body-parser": "~1.0.0",
"debug": "~0.7.4",
"jade": "*",
"mongodb": "*",
"mongoskin": "*"
}
In app.js
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req,res,next){
req.db = db;
next();
});
This is the Part where i have given those details
use it like below
res.render("users/UserPage");
instead of
res.render("/users/UserPage");
When you say res.render('somefolder/file)
so it searches in views/someolder/file
. Because you are saying res.render('/somefolder/somefile)
so it should be getting confused with /
.
The path to file should be {appName}/views/users/UserPage.jade
.