Reload image after upload!?

I’m trying to create an upload script and got that. Its a profile image upload script so everytime a user chnages the profile image the name will still be the same: userid.jpg.

Is there a way to refresh my image if success…

if (success == 1){
   result = '<span class="msg">Image uploaded...<\\/span><br/><br/>';
   // Something here to tell my image to refresh? //
}

My image:

<img src="images/userid.jpg">

Hope this is understandable…

Thanks in advance…

I assume your using PHP to manage the upload so what you need to do is use something like a JSON array when returning the data back to the JS function and set the new image path within that. For example…

Javascript

$.ajax({
    success: function(data) {
        if (data.status) {
            result = '<span class="msg">Image uploaded...<\\/span><br/><br/>';
            
            if (data['image'].length > 0) {
                $('#img_id').attr('src', data.image);
            }
        } else {
            alert('Error!');
        }
    }
});

PHP

echo json_encode(array(
    'status' => true, // true = no errors | false = errors
    'image'  => $newImageURL
));

And yes… Thanks… Did the job :wink:

No problem