0

I am trying to force an image to reload as a cache issue. I tried to follow this example but my result is that the image cannot be found:

<img id="profile_image" class="profile" src="http://localhost/PDO/asset/user_image/201658.jpg#1495177084338" alt=" profile">

var base_url    = $("#base_url_side").val();

function myForeverFunc(){

    $.ajax({
        url: base_url + "TimeKeeping/get_latest_login",
        cache: false,
        dataType: 'json',
        success: function(data){
            $(".user_name").html(data[0].Name);
            $("#profile_image").attr('src', base_url+"asset/user_image/"+data[0].Userid+".jpg#"+ new Date().getTime());
        }
    });
}

myForeverFunc();
setInterval(myForeverFunc, 500);
Community
  • 1
  • 1
hungrykoala
  • 1,083
  • 1
  • 13
  • 28

2 Answers2

1

Change this line:

$("#profile_image").attr('src', base_url+"asset/user_image/"+data[0].Userid+".jpg#"+ new Date().getTime());

to

$("#profile_image").attr('src', base_url+"asset/user_image/"+data[0].Userid+".jpg?time"+ new Date().getTime());

and try again.

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
  • I did some experimenting and discovered that my image is not loading fast enough when my setinterval is triggered. – hungrykoala May 19 '17 at 07:34
0

Try using ? after jpg in your code like this

$("#profile_image").attr('src', base_url+"asset/user_image/"+data[0].Userid+".jpg?"+ new Date().getTime());