I want to check if a image with a certain extension exists, if so, i want to alert the extension otherwise "unknown". The detection part of the code works fine, but when I alert the imagevar the first time, the var is empty, when I add another alert the var has the correct value.
Does it take to long for the $.get command to complete or where does the delay come from?
var extension = 'jpg';
var url = 'someimagefile.' + extension;
var imagevar = '';
$.get(url)
.done(function() {
imagevar = extension;
})
.fail(function() {
imagevar = 'unknown';
});
alert(imagevar);
alert(imagevar);