I'm trying to send the 'name' variable to the client side, but it's only working when I run a respons.end()
when I use two, returns this error:
> 'Can't set headers after they are sent.'
Server
router.get('/:eventnick', function(req, res, next){
EventData.findOne({eventnick: req.params.username}, function(err, eventInfos){
var name = eventInfos.name;//0
res.render('event/eventpage/eventpage', {title: 'teste| '+ name},);
res.end(JSON.stringify(name));
});
});
Client
$(document).ready(function(){
var url = window.location.href;
var splitUrl = url.split('/');
$.ajax({
type: 'GET',
url:'/event/'+splitUrl[4],
success: function(data){
console.log(data);
}
});
});