Sirine Abed Sirine Abed - 2 years ago 83
Node.js Question

Can't get ejs file

I need to call an ejs file in another ejs file and exactly in function but i have always "can not get file"
If i do an include file outside the function.It works.
But I need to call this ejs file in the function.

<input type = "submit" value = "heure" id="sub" style="width:120px" onclick="changer()"/>
<input type = "submit" value = "journée" id="sub1" style="width:120px" onclick="changersub1()"/>

<script type="text/javascript">
function changersub1()
{
document.getElementById("sub1").style.backgroundColor="MistyRose";

document.getElementById("sub").style.backgroundColor="white";

window.location = "./index1.ejs";
}
</script>


Do you have any idea please? Thanks

Answer Source

with the following line

window.location = "./index1.ejs";

you are trying to call something like localhost:5000/index1.ejs which is wrong. Index1.ejs is a template file which needs to be rendered on the server side as follows in ExpressJS

router.get('/index1', function(request, response) {
   response.render('index1.ejs');
}); 

add the above line to your routes and change the function to following

window.location = "/index1";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download