So yesterday, after all of the travel fun and games of the few days, it was back to the real world with a bump. I had a pile of bugs to fix on various projects. Most were very simple to get through, but one has taken me several hours to track down so I thought it would be useful to record the problem and my solution.
In IdeaJam we use Mootools as I have mentioned many a time before. Mootools, when executing Ajax requests does some very funky stuff to make the request as efficient as possible. One of those things, is that will detect the content type of the page you’re requesting and try it’s best to process it as it should, that is, if you request Javascript then it will try and execute it. Unfortunately if you’re in IE, then it uses the following technique
window.execScript(code)
This is all well and good until there is an error in the Javascript it is evaluating (and it is very picky about syntax here). When there is an error you will get something like:
Could not complete the operation due to error 80020101
There are a *lot* of websites out there where people have come across this problem and then tracked it down to a specific problem with their code so they assume that this error message means you should remove comment tags from your script, or there’s a missing semi colon on the end of a line, or an array is incorrectly formed. All of these may well be true, but the error message just means “There is an error”, you can read no more into it than that.
Instead, you need to look very closely at whatever is being returned and evaluate it manually yourself to track down the issue.
What was especially galling for me, is that my problem was entirely my own fault. I had set the content type of the page I was requesting using Ajax to be text/javascript when it actually it should have been text/html. So Mootools was trying to evaluate some “code” which could never possibly work. So my fix was simply to change the content type of my response page.
The point is that your problem may be something entirely different, and you’d still get exactly the same error message from IE. Thanks for that Microsoft.
#7HoursOrLess…
Great work tracking this bugger down mate.
So "80020101" = MS #Fail.
I want that on a T-shirt 🙂
Sorry for my English. Thank you! Got rid of the error IE! Required to follow very closely the syntax of scripts…
Thank you for posting this! Had the same problem, in my case Rails (3.0.9) rightfully added text/javascript as Content-Type header to my Ajax response (format "js", as that is what the XHR requests with standard UJS driver). Nothing wrong there, except that the JavaScript response wasn't JS, but just a piece of HTML that needed to be inserted into a container. Of course my own fault, but never noticed any problems in Firefox and other browsers before… Hope some of the keywords in this response help other people find this post.
Great job and thank you for sharing.
I’m stunned about myself that after all the years MS’ incompetence still surprises me.
Nice work man. Forgto to close script block – IE was the only browser complaining…
How can I remove the email address that caurse error
I tried to put an html-comment inside a script block, same error.
Removed <!– !> comment from script tag solved problem
I had missed to put ‘var’ in front of variable declaration, putting that it solved the issue.
<script>
uploadDocument = "Some message";
</script>
I fixed it to
var uploadDocument = "Some message";
Root cause was that I had an element in the form with the same id "uploadDocument", hence the above declaration was causing the html to be malformed
To reveal the error reason, you could run your code in IE. E.g. create a simple html page with script tag inside, open it in IE and you’ll get all the errors in readable format