Currently there is a form in home page which allows us to submit data. After data is saved, displaying the same .html page but different div (message like - Congrts, your poll is created ....). For this I am sending a boolean var dataSaved while sending file so that i can retrieve the boolean var & display the div.
My server.js looks like this -
app.post('/home/newPoll', function (req, res) {
const newPoll = new PollModel({
............//something here
});
PollModel(newPoll).save(function(error, data){
if (error) {
throw error;
console.error("User Data is not saved."+error);
} else {
console.log("User data saved successfully");// working fine
res.sendFile(__dirname+'/views/home.html', {dataSaved: true}); // this page is displayed also
}
});
});
if this var dataSaved is true, I want to display the div.
$(document).ready(function(){
............// some more code here, are working fine.
const dataSaved = <%= dataSaved %>;
console.log(dataSaved); // not getting this
if (dataSaved ) {
$("#newPollDiv").hide();
$("#myPollDiv").hide();
$("#pollCreated").show();
}
}
I am not using any view template.
kindly suggest, also if any other way to do this.
via jay thakur
No comments:
Post a Comment