DataJS-1.0.3 Breaks HTML page

Jul 9, 2012 at 10:54 AM

Hi,

I am just starting out with DataJS, and when I include the script, the html tags after the include line fail to be parsed by the html dom correctly. I am testing this with an empty asp.net webform and IE9, although it is also true with Chrome.

So, in my <head> element, I have the following line:

<script src="Scripts/datajs-1.0.3.js" type="text/javascript">

But the closing tag "</head>", and everything beyond is simply parsed as text (instead of html), when viewing the document in IE9 tools.

It suggests to me there's a syntax error in the javascript. I can actually get datajs to work, if I place it at the end of the html document, etc.

Thanks,

Mike.

Jul 9, 2012 at 11:19 AM
Edited Jul 9, 2012 at 11:19 AM


FYI - if I add an extra script element beneath the datajs include statement, containing just a semi-colon, it seems to work. eg:

<script src="Scripts/datajs-1.0.3.js" type="text/javascript" />

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

As a workaround.

Jul 9, 2012 at 5:35 PM
Edited Jul 9, 2012 at 5:37 PM

Hi Mike,

   Actually, the problem is that the script tag in your first post is not properly closed.  That will cause the browser to incorrectly interpret the rest of the HTML document.  Even using a self closing script tag, like in your second post, will not necessariliy work. Those aren't sanctioned by the HTML standard yet, and is up to the browser to support them or not.  See here for more details.

   Now, the workaround above works because the second script tag is properly closed, thus causing the browser to stop interpreting the html content as part of the first script tag.  You can remove this extra tag and close the one in which you include datajs and everything will work fine:

<script src="Scripts/datajs-1.0.3.js" type="text/javascript"></script>

Regards,

Alex Trigo

Jul 9, 2012 at 6:06 PM

Thanks Alex,

That solved it.

...and I thought self-closing elements were part of the xml specification!

Interesting link, cheers.

Mike.

Jul 9, 2012 at 6:41 PM

Hi Mike,

    Indeed self-closing elements are part of the XML specification... but not of the HTML one :). 

Regards,

Alex Trigo.