0

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.

wawanopoulos
  • 9,614
  • 31
  • 111
  • 166

1 Answers1

1

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(/*...*/);
ben
  • 3,558
  • 1
  • 15
  • 28
  • I tried your code but it's te same result. I doesn't see the content really created. I see that the content of document is the content of the data variable.. – wawanopoulos Jun 23 '15 at 13:19