Reputation: 9794
I use the following code to retrieve all images name from a specific folder :
$(document).ready(function() {
var loc = "../images/test/";
var fileextension = ".JPG";
$.ajax({
url: loc,
success: function (data) {
$(data).find("a:contains(" + fileextension + ")").each(function () {
var filename = this.href.replace(window.location.host, "").replace("http:///", "");
$("body").append($("<p>test</p>"));
});
}
});
});
Problem is that i go in success callback but i never enter in the loop to create my elements.
The content of "data" is a html page but when i want to parse the content of data variable, the page is not yet created.
Please have a look in this jsFiddle : http://jsfiddle.net/0rdv9jy5/2/ On HTML section, it's the content of the data variable.
Upvotes: 0
Views: 141
Reputation: 3568
Try to use a documentFragment. Basically, you create a documentFragment, you put the data in. And then you search from there:
var $html = $(document.createDocumentFragment());
var $fragment = $(data);
$html.append($fragment);
$($fragment).find(/*...*/);
Upvotes: 1