Question

In our current project some code is returned with AJAX and we use innerHTML to place this code inside a DIV.

Now we search this DIV for all available script tags and EVAL() the contents of these script tags (adds some information to a global array, etc)

scriptTags = responseElement.getElementsByTagName("script");

for (i = 0; i < scriptTags.length; i++) {
            eval(scriptTags[i].text);
        }

This works perfect in Firefox and Chrome. But in IE scriptTags appears to be empty. Upon further investigation it seems that the innerHTML of the responseElement doesn't contain any SCRIPT tags (while in Firefox / Chrome they're there!)

Anyone know the cause and/or work around?

By the way, this is how I put the AJAX response on the page:

this.proxy.innerHTML = o.responseText;
scriptTags = this.proxy.getElementsByTagName("script");

Debugging o.responseText shows the SCRIPT tags inside the response. Navigating to this.proxy element on the page shows no SCRIPT tag in IE but does show up in Firefox / Chrome.

Était-ce utile?

La solution

The problem was fixed by adding an additional node element before the SCRIPT tags that were in de AJAX response. (solution/cause: http://allofetechnical.wordpress.com/2010/05/21/ies-innerhtml-method-with-script-and-style-tags/)

In the future we should change our application so that the HTML is sent back as JSON.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top