As a simple fix you could change your success function to something like this:
function (data) {
$(data).find("a").attr("href", function (i, val) {
if( val.match(/\.(jpe?g|png|gif)$/) ) {
$("#galleryColumn"+(i%2?'One':'Two')).append( "<img src='"+ folder + val +"'>" );
}
});
Although this will not be the quickest way of doing it and it would get "out of sync", when there are <a> links in data that do not point to images.
A better solution would be
function (data) {
var imgs=[];
$(data).find("a").attr("href", function (i, val) {
if( val.match(/\.(jpe?g|png|gif)$/) ) {
imgs.push(folder+val);
}
});
$("#galleryColumnOne").append( "<img src='"+imgs.filter((v,i)=>i%2).join("'><img src='")+"'>" );
$("#galleryColumnTwo").append( "<img src='"+imgs.filter((v,i)=>(i+1)%2).join("'><img src='")+"'>" );
}
My answer is not tested, therefore no guarantees. But the main idea is to get the .append() part out of the loop over the individual links. This way the (slow).append() function will only be called once for each div. The contents (an HTML string) is prepared by using a fast Array.filter() and .join() operation.
There is one further point I would like to remark upon: You are using the expression
$(data).find("a").attr("href", function (i, val) {...});
to loop over <a> elements in your data HTML string. It works, as you have confirmed. I was puzzled, why you used this function, as its primary purpose is to set the href attribute of each matched element. After having had a closer look at the jQuery .attr documentation it became clear to me that this is a valid way to directly access the chosen attribute value for all matched elements and do something with it. As long as the function does not return anything, the attribute will remain unchanged. However, the more conventional way of looping over DOM elements with jQuery would be:
$(data).find("a").each(function (i, elm) {...});
elm is the DOM element and you would get its href attribute with elm.href.
var col=1col = col==1?2:1if (col==1) {} else {}