26

I get the following syntax error in Firebug and I don't get what's it:

> syntax error [Break on this error]
> <!DOCTYPE html PUBLIC "-//W3C//DTDXHT...org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n

Is it because of the final "\n" at the end ?

thanks

ps. I've just realized if I remove all scripts, I don't get that error. For example, if I remove these lines, I don't get it. If I add another script I get it again, so it doesn't depend on the script itself.

<script type="text/JavaScript" src="<?php echo $base_url; ?>sites/all/themes/bluemarine/js/main.js"></script>

CODE:

<?php
// $Id: page.tpl.php,v 1.28.2.1 2009/04/30 00:13:31 goba Exp $
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language->language ?>" xml:lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
<head>
  <?php print $head ?>
  <title><?php print $head_title ?></title>
  <?php print $styles ?>
  <?php print $scripts ?>
  <script type="text/JavaScript" src="<?php echo $base_url; ?>sites/all/themes/bluemarine/js/main.js"></script>
  <!--<script type="text/JavaScript" src="<?php echo $base_url; ?>sites/all/themes/bluemarine/js/griddy-min.js"></script>
-->

</head>

<body>...
1
  • Source code of the HTML file?
    – kennytm
    Commented Sep 25, 2010 at 9:31

5 Answers 5

27

Ryan Rampersad, blogged about this issue stating

The error comes from Firebug. The break on this error isn’t a part of the error but it is in the firebug copy dump....

syntax error [Break on this error] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML…3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

The way I encountered this error was that I forgot to specify a src attribute value for my script tag!

<script type="text/javascript" src=""></script>

Here is the blog post.

8
  • Thanks! The point is that all my scripts have "src". I mean, if I remove the last 2 lines (<script>) in the <head> then I don't get the issue. But they both have already src attriute
    – aneuryzm
    Commented Sep 25, 2010 at 9:41
  • Yes but are they real javascript? What is the Content-Type returned by the server? Commented Sep 25, 2010 at 9:44
  • oh you're right! one of them is considered html.. what am I doing wrong then ? The content of the first script (for example, is just a jquery function).. I don't think it is formatted badly
    – aneuryzm
    Commented Sep 25, 2010 at 11:28
  • uhm, how can I change it ? I'm actually storing it on my localhost and my local apache always worked correctly so far. Also, on another website on the same localkhost I don't have issues
    – aneuryzm
    Commented Sep 25, 2010 at 14:49
  • 1
    Here's the new link to the above blog post - blog.ryanrampersad.com/2008/09/…
    – Vandesh
    Commented Jun 6, 2014 at 4:11
15

I suspect that you have a <script> pointing to a URL that returns an HTML document (possibly it should be coming with a 404 response but isn't)

5
  • well, you see in the code they point to a js file. And in Firebug it is found (not 404 error is returned)
    – aneuryzm
    Commented Sep 25, 2010 at 9:41
  • 2
    Putting .js on the end of a URL doesn't make it a JS file. Servers (with some very rare exceptions) send HTML documents as the body of 404 errors. Sometimes they are misconfigured so they 404 error body comes with a 200 status code.
    – Quentin
    Commented Sep 25, 2010 at 11:32
  • what makes a js file then ? I just have javascript in it. thanks
    – aneuryzm
    Commented Sep 25, 2010 at 14:48
  • 1
    I had this problem, because the server returned a login page instead of the JavaScript file.
    – Tim Büthe
    Commented Apr 12, 2012 at 12:54
  • There was some advertiser JS file added to the footer of my page that was causing this error, thanks for the hint!
    – Kevin C.
    Commented Jul 7, 2012 at 0:30
2

In my case, when I received such error, the cause was "un authorised access" to the JS file.

To detect it, use FireBug, [HTML] tab: Try to expand each "script" node. one of these nodes contained the "401.html" page-content instead of the expected JS content.

2

I had the same issue. For me the problem was that I loaded a script file that pointed to nowhere or to be more precise it pointed to my domain root. The script declaration was <script src="http://mydomain/" type="text/javascript" />. What was happening was that the script was loading my home page. The first character of a home page is "<" because all html pages start with "<!DOCTYPE ......". Well this is a syntax error so and that was it. Once I eliminated <script src="http://mydomain/" type="text/javascript" /> everything was ok. I hope I helped you.

EDIT: In short, check your src pointers on your Javascript links to be sure they point at the correct files.

1
  • I was working on this issue from a long time. Thank you! You saved my job :-)
    – Mohit
    Commented Aug 28, 2015 at 14:31
0

I had the same problem. After trying many solution and searching about it, finally I got why I was getting that error.

I was getting that error because of invalid path in src attribute of script tag. Like I was adding script as below by simply dragging script on page from solution explorer in visual studio and I was getting error. My src attribute in script tag was src="~/js/jquery.min.js"

And I found that I was not getting script on that page.

So I used below solution to load script on that page. src attribute in script tag src="../../js/jquery.min.js"

Not the answer you're looking for? Browse other questions tagged or ask your own question.