Reputation: 3387
I have a python script that read and return (in JSON) every images from a specific folder. On a page, I have a form that allows me to add a new image to that folder: a simple upload form, a file input, when I submit it, it redirect me to the python script that upload it, and the python script finally redirect me to the upload form page, where images are loaded via AJAX.
Here is my JQuery code to get the required data via AJAX:
$.ajax({
type: "GET",
url: "images.cgi?action=list",
success: function (data) {
var parsed = $.parseJSON(data);
for (d in parsed) {
img = '<img src="images/' + parsed[d][1] + '" />';
$('div').append(img);
}
}
});
Images load fine when I get to the page for the first time. But if I upload an image, when I am redirected to the upload page, the last uploaded image is not loaded, and I have to manually reload the page to display it.
Thanks in advance for helping!
Upvotes: 0
Views: 255
Reputation: 3387
Well, my issue was due to the cache. I just had to set cache to false in my AJAX request and everything works fine now!
$.ajax({
type: "GET",
url: "images.cgi?action=list",
cache: false,
success: function (data) {
var parsed = $.parseJSON(data);
for (d in parsed) {
img = '<img src="images/' + parsed[d][1] + '" />';
$('div').append(img);
}
}
});
Upvotes: 1