Alex Rivera | Logout

Google Chrome: JavaScript Error Message

Asked 2008-12-26T05:58:26.133
17

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"> 

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

Edit
Report

3 Answers

14

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.

answered 2010-02-26T14:27:15.440
1

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&hl=en

answered 2008-12-26T07:09:59.200
1

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

answered 2010-02-08T06:01:24.137

Your Answer