IE: why is AJAX not the result of HTML updated in the DOM?

I upload html content via ajax to a div (using mootools 1.11 and squeezebox, if that matters).
In the downloadable content, I have several JSs that manipulate some loaded HTML objects.
Everything works fine in FF, but when I load it in IE (tested on IE7 at the moment), the code with the error "null" is null or not an object. A quick test shows that new items loaded by AJAX are not in the IE DOM. Loaded a div with id 'test', and when I ran document.getElementById ('test'), I got null. Needless to say, running getElementById on the source elements works fine.

Does anyone know how to solve this problem?

Additional Information: I placed my code in the "domready" window. I tried using the "load" event, but IE never called it.

UPDATE
as I advised, I tested the same script on IE8 as the best debugging features.
It seems that the problem is indeed in timing. I run my code in domReady windows and it seems to run instantly, without waiting for the DOM to be ready (in a popup window). Running the same script with the debugger, as soon as the whole page loads, detects elements without problems.
So I guess the question now is how to run the script at the right time.

  • The domready event seems to fire well before the house is ready.
  • The load event does not seem to fire at all
  • placing the script at the end of the file after the HTML objects also does not help
  • Mootools AJAX "evalScripts" true, script

?

+3
5

, IE dom. , "domready" innerHTML. :

new Ajax("someurl", {
    method: "get",
    evalScripts: true,
    onComplete: function() {
        $("someid").setHTML(this.response.text); // load content.
    }
}).request();

, , evalScripts . , script, , , ?

1.11:

onComplete: function(){
    if (this.options.update) $(this.options.update).empty().setHTML(this.response.text);
    if (this.options.evalScripts || this.options.evalResponse) this.evalScripts();
    this.fireEvent('onComplete', [this.response.text, this.response.xml], 20);
},

, : onComplete, :

update: $('somediv'),
evalScripts: true

. , :

new Ajax("someurl", {
    method: "get",
    onComplete: function() {
        $("someid").setHTML(this.response.text); // load content.
        this.evalScripts(); 

        // or if it fails still, delay it:
        /*
        if (window.ie)
        (function() {
            this.evalScripts();
        }).delay(100, this);
        */
    }
}).request();
+3

IE8 - IE, , , , - .

IE7, , IE8.

, , , .

+2

: - xmlHttpRequest fassion, , ? - DOCTYPE, , html/xml, IE - , , , , ? IE , FF. - AJAX DOM-, , , ? - HTML? , HTML, FF , IE .

+1

, Prototype answer:

new Ajax.Request('someurl', {
  parameters: param,
  onComplete: function(transport) {
    /* eval scripts first */
    transport.responseText.evalScripts();

    /* rest of onComplete code */
    /* ... */
  }
});

, onComplete (, Prototype 1.7.1, ).

+1

, - squeezebox mootools 1.2 ( setHTML, cfr , ); , squeezebox mootools ( IE)? , ( !).

0

Source: https://habr.com/ru/post/1720358/