- Where Developers Learn, Share, & Build Careers
I am trying to use Ajax to check that the image is present before loading it or not. I have done most of this work, but I am setting up a variable inside the error: and success: tag in AJAX, and it is not changing my IMG variable, do any of those tags affect the rest function The way? function getImage (imageNum) {var img; $ Ajax ({url: imageLocation + imageNum + '.png', type: 'HEAD', error: function () {img = 0;}, success: function () {var img = $ ('& lt; img / Gt; ', {src: imageLocation + imageNum +' .png ', category:' image ', id:' image '+ imageNum}); return IMG;}}); Console.log (img); Return img; } OK, if I have no reason to use AJAX, then I will only use the image tag. The problem is that the variable is not changing anything in my work. Here is an example function getImage (imageNum) {var img; Var success = 10; Var img = $ ('& lt; img / & gt;', {src: imageLocation + imageNum + '.png', catego...