I have a JavaScript function where I pass a path/name of a server-side directory in-order to return the paths/names of sub-directories to an array. Additional console.log()s were added in-order to check the flow.
Below function was sourced from this answer and then tweaked a bit to match the need.
function loadSubDir(dir) {
console.log("Initial method call with ", dir);
let res = null;
let path = null;
let xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", dir, false);
xmlhttp.send();
if (xmlhttp.status == 200) {
res = xmlhttp.response;
$(res)
.find(" td > a ")
.each(function() {
path = $(this).attr("href");
console.log("Values for Categories : ", path);
subDirs.push(path);
});
}
subDirs.shift();
return subDirs;
}
This works fine without any issue in my local Apache server where I use the default Apache configuration with only adding document root for the directory where this JavaScript file is available.
But if I use the same implementation on another Apache server environment, this FAILS. Having put logs, I noticed that "Values for Categories" log does not appear when running on server.
Is there any additional configurations needed or what could be the reason ?
Thank you!
The issue was how I have implemented $(res).find() method. In my local Apache server environment, the response was;
So.. $(res).find(" td > a ") works.. Since we were using Apache o docker, the response was;
here, instead of $(res).find("td > a") I needed to use the .find() method as $(res).find("li > a").
Then it continued the execution.