Lan Mai
Lan Mai

Reputation: 375

Ajax Get Files with multiple extensions

I currently found this code:

DOM_imgDir = "img/UI/DOM/";
fileextension = ".jpg";
$.ajax({
    url: DOM_imgDir, success: function (data) {
    $(data).find("a:contains(" + fileextension + ")").each(function () {
        filename = this.href.replace(window.location.host, "").replace("http://", "");
        $("body").append("<img src='" + DOM_imgDir + filename + "'>");
    });
}

With this method, I can only get from 1 file extension only. If I want to get files from multiple extensions, like "fileextension = ['.jpg','.jpeg'] , how can I do it? Thank you

Upvotes: 0

Views: 233

Answers (1)

user218046
user218046

Reputation: 633

use jQuery's multiple selector: $('obj1,obj2,other_obj').

DOM_imgDir = "img/UI/DOM/";
fileextension1 = ".jpg";
fileextension2 = ".png";
$.ajax({
    url: DOM_imgDir, success: function (data) {
        $(data).find("a:contains(" + fileextension1 + "),a:contains(" + fileextension2 + ")").each(function () {
            filename = this.href.replace(window.location.host, "").replace("http://", "");
            $("body").append("<img src='" + DOM_imgDir + filename + "'>");
        });
    }

Upvotes: 1

Related Questions