Disable cache on php and html with AJAX

前端 未结 1 781
旧时难觅i
旧时难觅i 2021-01-24 23:18

I use AJAX for my website and my website some part load after document is ready by AJAX and those parts are dynamic.

Example one part: Hello #USERNAME# this is different

1条回答
  •  走了就别回头了
    2021-01-24 23:28

    I believe this question is a little bit of a duplicate. However, if you want to ensure that caching does not happen on ajax calls, you can append a timestamp to the end of the URL you are hitting.

    Example in your JavaScript AJAX prep:

    var time_stamp = new Date().getTime();
    var myurl = "url_here.php?timestamp=" + time_stamp;
    jQuery.get(myurl, /* more parameters */);
    /* other relevant code */
    

    Here are some other sources from Google:

    • How to prevent a jQuery Ajax request from caching in Internet Explorer?
    • http://hungred.com/how-to/tutorial-stop-caching-jquery-javascript/
    • http://viralpatel.net/blogs/ajax-cache-problem-in-ie/
    • Stop jQuery .load response from being cached

    Another thing to consider is that it might not be a caching issue. Are you properly clearing any sessions/cookies? (If you are using them)

    0 讨论(0)
提交回复
热议问题