Why does this variable (lanFound) become undefined?
I get the following output:
Lightbulb moment! :)
As I typed the sequence of output gives it away! ajax is asynch, so the true comes back after the code has continued! I'll post anyway, might be handy for someone!
- testing for: DK
- result is: undefined
- /sites/cspdKnowledgeAssemblyPlatform/ApprovedContent/DKCover Letter.docx succeeded
I have a set of docx files, but am adding support for languages, but to test the files (docx) have been added I use the following code (OK this is a long had variant to allow me to debug):
fileUrl = filePath + fileName;
if (lan != "EN"){
showNotification("testing for: " + lan);
var lanFound = false;
lanFound = checkURL(filePath + lan + fileName);
showNotification("result is: " + lanFound);
if(lanFound){
debugger;
fileUrl = filePath + lan + fileName;
showNotification("found " + fileUrl);
}
}
function checkURL(urlFileName){
$.get(urlFileName)
.fail(function() {
showNotification(urlFileName + " failed");
return false;
})
.done (function() {
showNotification(urlFileName + " succeeded");
return true;
});
}
You can ignore this - just added for context of "showNotification")
function showNotification(content){
var currentText = $( "#resultpanel" ).html();
currentText = currentText + "<br/>" + content;
$( "#resultpanel" ).html(currentText);
}