0

This SO post explains how to include JavaScript specific to a page.

However, this method is causing this error in charges.js at line 1: Uncaught SyntaxError: Unexpected token <

In the Chrome console, the doctype declaration is highlighted as having the error.

The simplified view is below. The JavaScript file in question is empty.

Why is this happening?

<% content_for :javascript_includes do %>
  <%= javascript_include_tag "charges.js" %>
<% end %>

<style>
    #pageBox {
        width: 600px;
        margin: 60px auto;
    }

    .header {
        text-align: center
    }

    .content {
        margin-top: 50px;
    }
</style>

</div>
Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • I'll go out on a limb and say that the browser tries to load `charges.js` but the server returns a 404 html page. The browser, expecting JS code, finds a `<` instead. –  Jan 04 '19 at 07:59
  • @ChrisG that's a very sturdy limb you're on. :) please post as an answer so you can get credit. – Crashalot Jan 04 '19 at 08:44
  • It's basically a dupe of this: https://stackoverflow.com/questions/39230493/uncaught-syntaxerror-unexpected-token-in-first-line/ –  Jan 04 '19 at 08:55

0 Answers0