Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing Ajax loaded HTML content in IE
    primarykey
    data
    text
    <p>I have seen similar questions around, but none of them seem to have answers that help my case...</p> <p>Basically, I want to load some HTML in using <code>$.ajax()</code> (Which is on a different domain), and have it parsed into it's own DOM, so I can apply attributes and manipulate HTML in my actual window DOM.</p> <pre><code>$.ajax({ type: 'GET', url: 'http://example.com/index.html', dataType: 'html', crossDomain: true, cache: false, success: function(data) { var src = $('body img', data).first().attr("src"); //also tried: var src = $('body', $(data)).first().attr("src"); $('#someDiv img').attr("src", src); } }); </code></pre> <p>Where an example HTML file is:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;img src="someurl"&gt;&lt;/img&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>It works in Firefox, but not IE, no matter what I try, whenever I try to parse and read, it returns null. Any suggestions?</p> <p>EDIT:</p> <p>It appears there was some ambiguity with my question. The issue is the parsing, not the AJAX. The AJAX returns the html string correctly, but jQuery fails to parse it.</p> <p>EDIT 2:</p> <p>I found a 'solution', but it isn't nearly as nice as I wanted it to be, it chopping and sorting through the HTML string, and extracting data, rather than applying it to a DOM. Seems to run efficiently, as I can predict the order of data.</p> <p>Boiled down, it is something like this:</p> <pre><code>var imgsrcs = new Array(5); var searchItem = '&lt;img src="'; for (var a=0; a&lt;5; a++) { var startLoc = data.search(searchItem) + searchItem.length; for (var i=0; i&lt;data.length; i++) { if (data.charAt(startLoc + i) == '"') break; imgsrcs[a] += data.charAt(startLoc + i); } data = data.substring(startLoc + i, data.length); } $('.image').each(function(i) { $(this).attr("src", imgsrcs[i]); }); </code></pre> <p>Fairly ugly, but I solved my problem, so I thought I may as well post it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload