Sirine Abed Sirine Abed -3 years ago 142
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()


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

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) {

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