IE executes only last XHR request completely

40 Views Asked by At

my website loads additional stuff upon request via an XHR request. It works fine in Firefox but IE10 messes up. Basically, I loop over an array of 4 items representing 4 pages I might want to load. If the page does not exist the request is discarded. The following code creates a title for each section. The section is taken from the loaded web page and padded to fit into the main page.

for (var i=0;i<titleArray.length;i++){

    var xhr_file = xhr_files.replace("xhr_replace",titleArray[i]);

    var sectTitle = document.createElement("P");
        sectTitle.setAttribute ("class","section_title");
        sectTitle.appendChild(document.createTextNode(titleArray[i]));

    if (IsDocumentAvailable(xhr_file)){
        //alert(xhr_file);
        newItem.appendChild(sectTitle);
        var client = new XMLHttpRequest();
        client.open('GET', xhr_file);
        client.send();  

        client.onreadystatechange = function() {
            if (client.readyState == 4) {
                var FileTex = client.responseText;
                var parser = new DOMParser();
                var FileHtml = parser.parseFromString(FileTex, "text/html");                        
                var FileCon = FileHtml.getElementsByTagName("DIV");

                for (var index = 0; index < FileCon.length; index++){
                    var tags = FileCon[index].cloneNode(true);                      
                    var images = tags.getElementsByTagName("IMG");

                    for (var i = 0; i < images.length; i++){
                        var source = images[i].getAttributeNode("src").value;
                        var newSource = source.replace(/(\.\.\/)+/g,"");
                        images[i].setAttribute("src", newSource);
                    };
                    newItem.appendChild(tags);
                };                      
                newWrap.appendChild(newItem);
            };
        };
    };
};

Firefox creates nicely the titles and fills the section with the content of the web page. IE10 however seems to only load the last of the available items but creates titles for all existing web pages. In the network monitor of IE the XHR request is completed and the content is shown but not in the webpage. Oddly, when I uncomment the alert(xhr_file); everything is shown in IE10. So it seems that there is a timing error but I cannot figure out where. Synchronous request does not solve the problem.

0

There are 0 best solutions below