Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140071

Ejs compiled function does not execute script tag

$
0
0

I am trying to understand why my script tag is not being executed with EJS. I am using Express JS and EJS template engine. I am sending to front end a compiled EJS partial template:

router.get("/piechart/", async (req, res, next) => {
  try {
    const ejsPartialFile = await readFileAsync(
      "./piechart-title.ejs",
      { encoding: "utf-8" }
    );
    const data = {title: "something important"}
    let ejsFunction = ejs.compile(ejsPartialFile, { client: true });
    res.status(200).send(ejsFunction ({ data }));
  } catch (e) {
    console.error(e);
    next(e);
  }
});

Which also contains tag with javascript file:

<div class="form-group">
      <label>Edit Piechart title</label>
      <input
        type="text"
        class="form-control"
        name="piechart-title"
        value="<%= data.title %>"
        maxlength="10"
      />
    </div>

<script src="/javascripts/testing.js"></script>

The javascript just contains some random stuff which should be executed when it is read:

(function() {
  console.log("testing if javascript file is being read");
})();

However, what happens is that the html gets added with correct things, to the page, however, the javascript doesnt get executed and I get no error. I guess something blocks it? Maybe someone has an idea?

Regards, Rokas


Viewing all articles
Browse latest Browse all 140071

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>