I know this has been asked a million times, but I just can’t get this little thing working. I’m using ajax to see if a file exists, via php’s file_exists() and returning the jqxhr object. Ithen use another function to process the .done clause. I can’t seem to get the data back from the second function.
I’ve been trying everything I can find or think of for three days. This is my latest iteration.
/***** Image exist **/
function getExist (url) {
return $.get ("<?php echo $_SESSION['path']?>/ajax/existPic.php", {
"pic": url
});
}
/***** populate table row **/
function popRow (objItem) {
var imgIcon = "";
const strPic = "../pic/" + objItem.something + ".jpg";
const isPic = getExist (strPic);
strTable += donePic (isPic, objItem.something); // strTable is global
strTable += "<td>" + objItem.otherThing + "</td>";
}
function donePic(isPic, thing) {
isPic.done (function (result) {
strTd = "<td>" + thing;
if (result == "TRUE") {
strTd += "<img src='<?php echo $_SESSION['path']?>/image/camera.png'>";
}
strTd += "</td>";
alert (strTd); // get all the right answers here
return strTd; // nothing gets back to popRow
});
}