4

Strange error here: I have a page that's referencing several JavaScript files. Occasionally, the browser will complain of:

Uncaught SyntaxError: Unexpected end of input

However, it doesn't appear to be due to a missing parent, or malformed JSON. Part of the JavaScript file will load, but the program will just stop loading the rest of the file. Example: half of the file will load, with the other half missing.

Most of the time, the files load and everything works. Any idea why I would occasionally be getting this error, rather than every time (as expected with a missing paren or something similar)? Other things I can check?


EDIT:

  • This is a Rails project (Rails version 3.2).
  • The JS files are standalone, and are kept in the pub directory for dev. In other words, they are NOT included in the asset pipeline.
017Bluefield
  • 161
  • 2
  • 13
turing_machine
  • 443
  • 3
  • 12
  • 1
    Could you post the source? It'd make it easier to diagnose. Are the js files ajax or not? And have you run the files through jslint/jshint? – Eric Lagergren Jun 15 '14 at 04:58
  • 1
    Got a live link? Otherwise run your code through [jshint](http://www.jshint.com/) – Patsy Issa Jun 15 '14 at 04:58
  • 4
    This error is most likely due to missing a }. Can you please post the code. – Wayne Ellery Jun 15 '14 at 05:00
  • 1
    @WayneEllery I'll try and get some source posted, in the meantime: have you seen this error occur only occasionally when caused by a missing }? Wouldn't it break on every load? – turing_machine Jun 15 '14 at 05:53
  • 1
    If you are using ajax with json it could be failing sometimes due to parsing invalid json. – Wayne Ellery Jun 15 '14 at 05:58
  • 1
    What server are you using? What browser? Is this HTTPS? – in need of help Jun 15 '14 at 07:42
  • 1
    @inneedofhelp this is a Rails project, not SSL (since in dev mode). I'll update my questions with this info. I also added some info to the question about where the JS is being served from – turing_machine Jun 15 '14 at 07:44
  • 1
    Do you get the same error if use a separate static server for these? E.g. nginx, http-server, etc? – jokeyrhyme Jun 15 '14 at 20:18
  • I sometimes see this behavior when I am working with code that stores JavaScript code in a string and the string is not escaped properly for the context into which it is being loaded (e.g., if it's being loaded into the src attribute of an iframe, or eval'd, or written to the page using document.write). You might check your JS files for these possibilities. – fgshepard Aug 18 '14 at 16:17
  • Agree with @WayneEllery this error occurs when there is a missing } . It maybe occurring for responses which are in some way syntactically incorrect so therefore occasionally and not always – user3260861 Aug 19 '14 at 04:44

1 Answers1

-2

There must be braces not closed properly.The file stops loading whenever the error is encountered and leaves the rest part unloaded as because of error. You can check this example here

Community
  • 1
  • 1
Abhishek Pachal
  • 544
  • 6
  • 24