How to load a JSON file via AJAX?

I’m trying to add a .json file to my Grav site and access it via AJAX (JQuery), and I did what it says here:

  1. Created the twig file at /templates/myfile.json.twig.
  2. Put the JSON data into that twig file.
  3. Went to localhost/myfile.json.
  4. Browser says “Woops. Looks like this page doesn’t exist.”.
  5. But it shows up when I include it in base.html.twig, for example, with {% include 'myfile.json.twig' %}.

But I’d like to access the JSON file via AJAX, not as an include. How can I do that?

Please help.

Do you have a page with the /myfile slug? If not, no wonder you get the error