1

i need to replace the uploaded image with the previous image with same name and size and after sucessfull upload refresh the div to show the new image .everything is working fine except that the new image is not updated on ajax load method i have to refresh the whole page to do so.

hare is related code

var options = {
        target:   '#imager778',   // target element(s) to be updated with server response 
        beforeSubmit:  beforeSubmit,  // pre-submit callback 
        success:       afterSuccess,  // post-submit callback 
        resetForm: true        // reset the form after successful submit 
    };  
     $('#MyUploadForm').submit(function() { 
        $(this).ajaxSubmit(options);            
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    });
    function afterSuccess()
   {
    $('#submit-btn').show(); //hide submit button
    $('#loading-img').hide(); //hide submit button
    $("#divofimage").load("page.php #divofimage");
    }

can any one suggest me anything i think ths is because of caching i have already tried ading random numbers to the url but no effect

7
  • You should add random string to new image url, something like url + '?r=' + Math.random() Commented Aug 15, 2014 at 4:19
  • already tried but no effect Commented Aug 15, 2014 at 4:20
  • what is response from page.php? Commented Aug 15, 2014 at 4:22
  • on refreshing the page the image gets updated to it. but not on ajax load the image is going to database and to the server Commented Aug 15, 2014 at 4:27
  • no, i mean, page.php serving raw image or <img src="url"> ? Commented Aug 15, 2014 at 4:36

1 Answer 1

1

We can break the cache of browser by forcing the image through ajax and then associating the new image with the timestamp .

var name='FULL_PATH?dt=' + (+new Date());
$('<img src="'+name+'">').load(function() {
       $('#ID').html('');
       $(this).width('40').height('40').appendTo('#ID');
});

and you have got the nice and cool new image :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.