views:

5477

answers:

10

When using Google Chrome, I receive the following error message:

Error:

Uncaught SyntaxError: Unexpected token <

It occurs directly after my doctype declaration at the top of my HTML page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

Any ideas what this JavaScript error message is? It only seems to occur with Google Chrome (works fine in Safari, Firfox and IE)

+1  A: 

Maybe the HTTP content type is not text/html or application/xhtml+xml?

orip
I would I determine the HTTP content type?
using firefox and firebug.
Pim Jager
+1  A: 

I found this Google Groups question.

Some others are experiencing the problem but without resolution.

http://www.google.com/support/forum/p/Chrome/thread?tid=7e9f87870a37e401&amp;hl=en

A: 

I started getting this error yesterday. In my case, it is originating from the WebResource.axd tags that ASP.NET puts into the page. It is very hard to diagnose, as it only happens in Chrome and Safari, and only after I upload to the server. If I run the site locally, there is no issue. Any help would be appreciated.

A: 

Are you still experiencing this issue or were you able to resolve it?

A: 

Exactly the same problem... :-/

JoelBillaut
A: 

Try switching the order of your css and js declarations. Worked for me.

Pooch
+5  A: 

This problem occurred for me when I was using JQuery to load in HTML from an XMLHTTPRequest that was HTML, but the mime type was text/javascript.

So for example, I had some code such as: jQuery.ajax( {data:'params=here', success:function(request) { jQuery('#country_list_container').html(request); }, type:'get', url:'/getHtml' } );

jQuery is sending a request to getHtml, and getHtml is returning a simple snippet of HTML, with a mime/type however of "text/javascript". The reason the getHtml action was returning text/javascript is because the accept header of the request from jQuery is: "Accept:text/javascript, text/html, application/xml, text/xml, /"

So, all I had to do was force a header of text/html and everything worked perfectly.

The parse error you are seeing is a result of Javascript trying to eval the content.

Matt

A: 

I had this problem when i was trying to set .innerHTML dynamicaly generated with php (it was generated multiline). Replacing new line characters by spaces solved the problem.

Dawid

dawid
+1  A: 

In my case it was caused by an eval() statement aborting. When I fixed the problem the error message disappeared.

At the present time (June 2010) Chrome Javascript has a buggy eval() statement. eval() will abort without issuing an error message if a variable in the eval() statement has been assigned the reserved word 'delete'. It took me almost a week to uncover this bug because eval() aborts without any warning or error message, and the abort has nasty side-effects.

I was using eval() to achieve this result: obj.delete = somevalue.

This code will cause an eval() abort: var obj = new Object(); var x = 'delete'; var y = 2; eval('obj.' + x + ' = y');

This code works: var obj = new Object(); var x = 'delete'; var y = 2; eval('obj[\'' + x + '\'] = y');

In summary, don't use eval() to construct obj.delete = somevalue. Use eval() to construct the equivalent statement obj["delete"] = somevalue.

BlackMagic
this also applies to "new"
Kinlan
A: 

If you are returning a response to an ajax request in JSON, make sure you use 'application/json' for the Content-Type.

Sacha