4

I'm having a strange issue where IE8 is reporting a JavaScript error outside of a script tag (or so it claims), and breaking all further JS on the page. Here is the offending code:

<script type="text/javascript">//<![CDATA[
    function emailReport() {
        var params = window.location.search;
        var url = "scripts/someScript.php" + params;
        ajaxwl(url, false, null, function() {
            alert("Report successfully sent.");
        });
    }
//]]></script>
<h2>Analyst Report</h2>

ajaxwl() is just a wrapper over jQuery.ajax(), and is used in hundreds of places throughout the site with no issues.

IE claims the syntax error (it doesn't elaborate as to what type) is at character 23 of the line with the </script> tag. This is especially strange since that line only has 15 characters. If I inspect the supposed location in the IE8 developer tools, however, it actually puts the error in the middle of the <h2> tag on the next line.

Here is the official IE error message:

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; InfoPath.1; MS-RTC LM 8)
Timestamp: Tue, 12 Jun 2012 21:19:38 UTC


Message: Syntax error
Line: 175
Char: 23
Code: 0

Given that IE doesn't tell me an actual error message, I haven't been able to find anything about this online so far. JSLint doesn't yield anything helpful either, and it works flawlessly in Chrome and FF. Am I missing something obvious?


EDIT: My hunch is that despite IE reporting the error in the code snippet above, it's actually dying somewhere else. That seems to be the consensus. I guess I'll scour the page and see if I get lucky and find the error.

10
  • What happens if you remove the CDATA (opening and closing tags)? Commented Jun 12, 2012 at 21:28
  • Does it make the Ajax call? What is the URL returning? Maybe it tries to evaluate the response as JavaScript. Commented Jun 12, 2012 at 21:28
  • You have an XML CDATA section, are you using an XHTML doctype? Commented Jun 12, 2012 at 21:29
  • The doctype is XHTML 1.0 Strict. Removing the CDATA makes no difference. An AJAX call is made, but returns nothing. Commented Jun 12, 2012 at 21:34
  • I would suggest opening the file with an hex editor and checking if there aren't any funny invisible control characters before the newline between </script> and <h2>. Commented Jun 12, 2012 at 21:39

2 Answers 2

3

IE is notorious for not specifying the file where an error occurs, or not specifying it correctly. Try running it in the IE debugger and see if the error isn't on line 175 of a different file altogether.

EDIT Debugger didn't work, so you are going to have to do this the hard way: save the page to your disk; concatenate all the Javascript files into one big file; include that file from an otherwise blank page. Now the line number will be different, but accurate in the only JS file you have.

My prediction: terminal comma. The following line of code is legal in Javascript, but not in IE "JScript".

 var x = [ 0, ];

"Steve Jobs is dead and Bill Gates is alive because there is no god. But 100 years from now, Jobs will be remembered with Edison and Eli Whitney while Gates will be forgotten, because there is justice."

Sign up to request clarification or add additional context in comments.

3 Comments

Good call, tried that out as well. I was able to get the debugger to run twice before it crashed IE, but it didn't catch anything either time. My hunch is that because IE thinks it is a syntax error, not a runtime error, the debugger won't break on it.
The fact that you remember Edison and not Tesla, says you're wrong :)
I remember Tesla -- but I also remember he was fooling around with death-rays and bladeless turbines while Edison was changing the world.
2

I just fired up my windows box running IE 8.0.7601 and have no syntax issues being reported with this code

<?xml version="1.0" encoding="utf-8"?>
<!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" xml:lang="en" lang="en">
 <head>
   <title>I AM YOUR DOCUMENT TITLE REPLACE ME</title>
   <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
   <meta http-equiv="Content-Style-Type" content="text/css" />
 </head>
 <body>
   <div>

<script type="text/javascript">//<![CDATA[
    function emailReport() {
        var params = window.location.search;
        var url = "scripts/someScript.php" + params;
        ajaxwl(url, false, null, function() {
            alert("Report successfully sent.");
        });
    }
//]]></script>
<h2>Analyst Report</h2>


   </div>
 </body>
</html>

4 Comments

The // is necessary. Removing it causes the browser to interpret <![CDATA[ as a JS command, which it is obviously not.
I copied your code from the question, ran it through the HTML Validation service and it generated the extra boiler plate XHMTL tags etc. Try copying from my answer and viewing in IE.
That works fine for me too. Seems IE is reporting an error in the wrong location. Ugh.
What a pain! You'll just have to remove script sections piece-by-piece until you find it :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.