1

I have this code in index.html

$(document).ready(function() {

$('#generate').click(function() {

//$("#results").empty();
$("#results").html("");

$("#results").load("generate.php"); 

});

});

Also, I have this code in generate.php :

<?php

$img1 =  "<img src='logo_0.png' width='350px' height='350x' /><br />";
$img2 =  "<img src='logo_1.png' width='350px' height='350x' /><br />";

echo $img1.$img2;

?>

If I replace these images with different images (manually by copy & paste but keeping their names), I still get same images,

I assumed that happens because the dom objects are already created, so I tried

$("#results").empty();

and

$("#results").html("");

but images don't change,

Thank you

eawedat
  • 409
  • 2
  • 8
  • 17
  • What happens if you reload the page? If you're really not changing the names, it's likely that the browser is just redisplaying the cached copies of the original images. – Paul Roub May 02 '17 at 14:57
  • Sounds like a caching issue to me. On chrome if you have the console open (right click and go to inspect element) then you can right click on the reload button and choose "Empty Cache and Hard Reload", if you are having a cache issue this is best way i know of to clear it on Chrome – victor May 02 '17 at 14:58
  • @PaulRoub, reloading the page still requires you you to press on the generate button again, I mean I can do "reload" then press on "generate" and that will work. The thing is I was seeking once you press on "generate" button without the need to "load" the page each time, – eawedat May 02 '17 at 15:05
  • @victor, I tried also Firefox, I get same results as in Chrome, so it seems that something should be done in the code – eawedat May 02 '17 at 15:06
  • Caching most likely, generate random numbers behind your images eg. image.jpg?v= – Niek van der Maaden May 02 '17 at 15:27
  • @Niek van der Maaden , then I will be facing space issue :( imagine that i'm working with thousands of images, I just thought to overwrite their names – eawedat May 02 '17 at 15:44

1 Answers1

0

I was going to add a comment but didn't have enough reputation. What about adding the current date/time to the end of the URL to make it unique with the goal of preventing the browser from loading from cache?

You could also use an $.ajax() function to control cache or turn if off for all requests. See this answer for more details.

Community
  • 1
  • 1
Damajj
  • 68
  • 5