Thursday, October 23, 2008

Javascript console syntax error on Doctype

I just solved an interesting problem.

There was a Doctype syntax error in the console.

This was caused by an invalid javascript file included on the page - invalid meaning there is no file in the src tag, or the file does not end in .js.

The fix was to remove the CMS code that was inserting an empty javascript tag with no src file.

Tricky to track down, simple to fix.

31 comments:

Anonymous said...

Thanks!!! Saved me a headache, that's for sure :)

jon said...

cheers!

Nicolas said...

Thanks a lot, you saved my day...

Marvin said...

Thank you very much it saves a lot of my time. :)

Unknown said...

have no idea how you would find that, but that's a great tip to fix an annoying problem.

Unknown said...

<3

In my case it was both. The wrong file extension was a typo and therefor pointing to a non-existant file.

Joyel said...

I appreciate that. I was fighting with this issue for a long time. I read what you said and started looking at the possibility that the file was loading incorrectly and realized I had named the JS file wrong. That was a waste of 3 days. Thanks, your post helped me figure that out. Thanks again.

Robert L said...

Thanks alot!

Unknown said...

Saved Me DAYS of frustration. I had to include ALL of the .js files that come with script.aculo.us to avoid this error.

jklmnop said...

i've found that it's also caused by an empty js file in firefox too.

so if the file exists, but it has nothing in it, it will in some cases trigger this error.

adavydow said...

Thank you. I spent a day trying to recognize where the problem is.

Anonymous said...

Thanks. You saved my world.

Anonymous said...

Thanks man, this one helped me out

Mitul said...

Thanks. It saved a lot of my time.

Anonymous said...

Wow, check this. I had accidentally typed a "0" in my google analytics code and changed the domain. Since it was an invalid domain, comcast (my isp) was feeding back a 404 page from their dns server which was causing this syntax error. So, it may not even be your code doing it! Thanks for the heads up!

Sum-Wai Low said...

thanks!! error gone now

D said...

Thank you, that's saved me a lot of stress.

This happened for me when I transferred my work from my local machine to a remote server - a syntax error in the DOCTYPE of all things, and none of my javascript working. It's obvious now that I forgot to check in the javascript file to source control, but in my sleep-deprived state I could have spent hours investigating server configurations and finding out if some doctypes only work on localhost.

eli said...

Thanks, saved me some time.

Nick said...

Brilliant, thank you! I found out that I was referencing a .js file with a hyphen instead of an underscore very quickly after reading your post.

Aaron said...

Still helping. Thanks for your info.

Anonymous said...

Thanks! For me the error came from having ajax (jQuery) autocomplete calls to a non-existent ajax source. Your post helped me focus on the javascript instead of spacing or syntax in an html file ... lots of time saved! Thanks again.

said...

Thanks Very Very Much! That's the exact SOLUTION !

Didi12 said...

Thanks dude! 3 years later you're still helping people!

Anonymous said...

Phoarrh. Dude! Thanks a million. This saved my evening.

Unknown said...

Great work.Thanks alot!

Pradeep Prajapati said...

Thanks Dude. There was problem with ajax request and it tells in Java Script console syntax error in line 123 Doctype. It was because of ajax response was wrong means ajax response of requested page contain js but due to html (header and tag) it was unble to execute js.
Now I have resolved my problem.

After all problem was due to JS function.

mccormicky said...

Hey thanks - helped me out just now on my project

Anonymous said...

Thanks!

Anonymous said...

thanks

Chris said...

Another thing that can cause the same error. Is a javascript file (.js) that is empty, nothing in it, no lines, etc..

why you might have a blank file could be for so much as a place holder for something your working on or intent on working up soon. Or for whatever reason, anyway. Quick fix for that is simply just putting a comment into the file if anything else

Jamspal said...

Awesome Catch! i am used to a Windows environment and recently started working on an Ubuntu server...capitalization counts!