image thumbnail not refreshing on ajax.reload
image thumbnail not refreshing on ajax.reload
i have a table with json sourced via editor/ajax with some images.
i have added a tool to enable me to crop the uploaded images via a bootstrap modal and save the cropped image onto my server, and i want to display the updated thumbnail in my table, on closing the modal.
$('#EditImage').on('hidden.bs.modal', function () {
console.log('start');
$('#example').DataTable().ajax.reload( null, false );
console.log('end');
})
my console is showing no errors, but the thumbnails are not updating in my table (unless i reload the page)
i even tried adding
setInterval( function () {
console.log('x');
table.ajax.reload();
}, 5000 );
so the table would refresh every 5 seconds, but still nothing
This question has an accepted answers - jump to answer
Answers
Can you link to the page so I can take a look?
Thanks,
Allan
Hi Allan
I created a vanilla test page here...
http://www.test.forthwebsolutions.com/_slideshow.php
i think i realised what the issue is (but don't know how to fix it).
The database row is not being updated, just the image itself, so i am being presented with the image in the cache as the url of the image is the same
i could append a timestamp on the image name and update the table, but would prefer not to have to do this,
I have seen posts regarding adding a timestamp to the underlying query, but can't see how to implement this with editor ajax
You should resolve this with some kind of trick by using a timestamp. You do not need to change anything in your ajax calls. Only in the render functions. As Ajax will not send you an image but only a reference to the image. If you append a timestamp to your render function the cache will think it is another image and will load this.
In your render function only add something like this after the image source:
But you have to find out some strategy that will prevent that all your images are reloaded while they are still unchanged. So maybe you can think in some kind of a version number for each image.
Perfect !
I updated the render function as you suggested and it works perfectly.
Only a few images at the moment, but i will also work out how to refresh the selected row only rather than the whole table
Cheers !!