I have a button #myButton that has a link to an image that will be created by a PHP script createImage(). I need to fire the createImage() and then check to see if the image is there isImgThere(imageLink);.
The problem is that my code just runs through the isImgThere(imageLink) function and does not wait until true before the link is triggered. How do I get the isImgThere(imageLink); function to finish only when success? I have tried using while statements but none have worked.
$('#myButton').on('click', 'img', function() {
    createImage(size);
    isImgThere(imageLink);
});
function isImgThere(imageLink) {
    $.ajax({
        url:imageLink,
        type:'HEAD',
        error: function()
        {    
            alert("false");
            return false;
        },
        success: function()
        {    
            alert("true");
            return true;
        }
    });
}
This is the create an image function:
function createImage(size) {
    var myImage = ZoomAddress + 'php/zoom.php';
    var myPram='random='+random+'&returntype=3&size='+size+'&Views='+imgViews+'&'+WhatZoom;
    $.post(myImage,
        myPram,
        function(data) {
    });
}
 
     
    