This is a dilemma I have been chipping away at. I can't seem to figure out the best approach here.
I have my server pull multiple json files to one single directory and the json files are all in the same structure. Each of the files have a randomly generated file name.
My end goal is to append certain elements of each json file to an easily readable html table.
Here is my current code that works great with a single json file:
$.getJSON('testing1.json, function(data) {
$.each(data.user.products, function () {
$("table").append($("<tr>").append(
$("<td>").addClass("Title").text(this.title),
$("<td>").addClass("Price").text("$"+this.price),
$("<td>").addClass("Stock").text(this.stock),
));
});
});
Now I need to figure out the best way to go about my issue. I have ~250 json files I need to loop through. Obviously this regex wont work but may give you an idea of what I am trying to do:
$.getJSON('*.json, function(data) {
I would prefer to not have to merge them all into one single file. But the fact all the names are randomly generated, and I don't know how to load multiple json files into my code, I am worried I will have to do this. But it wouldn't be the end of the world if this was the case.
Is it possible to use Jquery/PHP to loop through the directory and pull all the json files? If so how would one go about loading each json file to append data from?
I really appreciate the help in advance, even a push in the right direction is much appreciated.