I'm using a call back function which will check for 60secs. If file avaible then will return true else will return false. The call back function I'm calling after ajax call.. Here is code below :
$.ajax({
type: '..',
url: '..',
data: '..',
success: function(data) {
window.loadFile(data);
}
})
window.loadFile = function(filePath) { // I'm getting the data. Now passing to call back function
$.when(window.waitTillFileExistsAndLoad(filePath)).done(function(data) {
alert(data) // here data is giving me undefined..
});
}
var timer = 0;
window.waitTillFileExistsAndLoad = function(fileName) {
var checkFile;
return $.get(fileName, function(data) { // If file found..
timer = 0;
return true;
}).error(function() { // If file not found..
timer += 1;
if(timer == 30) {
timer = 0;
clearTimeout(checkFile);
return false;
} else {
console.log('error occured');
checkFile = setTimeout(function() {
window.waitTillFileExistsAndLoad(fileName);
}, 2000);
}
});
}
The issue is that when I'm using $.when()
it's giving me undefined. Please suggest me what's wrong in my code.