0
I’m trying to send the variable 'name' 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);
}
});
});
In case I could not use both? The two I say the two res.
– Vinnicius Pereira
In case, I’m trying to send the variable and render!
– Vinnicius Pereira
This is not possible! After using one or the other you will be sending a reply, it is not possible to send two reply to the same request!
– Lauro Moraes