Online Promoters™ :: Web Development made simple

Prototype IE7 error – evalScripts crash


Let's assume that you load some content - that contains javascript code - into a div using prototype's Ajax.Updater.

You may want that javascript code, from the ajax response, to be evaled. So, you would do something like:

[sourcecode language="js"]
<script language="JavaScript" type="text/javascript">
new Ajax.Updater('the_div_id','/php_page',{evalScripts:true, onFailure: show_error});
</script>
[/sourcecode]

The error thrown by IE7 ironically is generated by the comment lines :[sourcecode language="html"]<!-- ... // --> [/sourcecode] from the Javascript code found in your ajax response:

[sourcecode language="js"]
<script language="JavaScript" type="text/javascript">
<!-- alert( 'Hello' ); // -->
</script>
[/sourcecode]

If you remove the comments, the non-commented javascript code will work:

[sourcecode language="js"]
<script language="JavaScript" type="text/javascript">
alert( 'Hello' );
</script>
[/sourcecode]
Firefox works whether the script is commented or not.

Source: http://knowledge.jamiehinton.co.uk