最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ajax load page without cache - Stack Overflow

programmeradmin1浏览0评论

I'm using this ajax function to reload an html page to a division in web page.

<script>
    $('#scene_container').load('scene.html', function () {

                cache: false
            });
</script>

html:

<div id="scene_container"></div>

But most of the time it loads cached webpage. How to load the original html page?

I'm using this ajax function to reload an html page to a division in web page.

<script>
    $('#scene_container').load('scene.html', function () {

                cache: false
            });
</script>

html:

<div id="scene_container"></div>

But most of the time it loads cached webpage. How to load the original html page?

Share Improve this question asked May 1, 2014 at 12:04 Asanka HerathAsanka Herath 1,6113 gold badges20 silver badges36 bronze badges 1
  • You set cache = false in the callback function. That does not have any effect on the ajax call. You should use the $.ajax function to disable caching. Or as @maj suggests use a url time parameter. – devqon Commented May 1, 2014 at 12:08
Add a ment  | 

2 Answers 2

Reset to default 5

Preventing cache is not available with the load method unless you disable it globally

But you can make sure no data will be loaded from cache by appending a time parameter to the request URL

url = "scene.html";
url += '?_=' + (new Date()).getTime();

To control caching on a per-request basis, you need to use a more plex function like $.ajax() .

Insert this at the top of your script:

$.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
});

MANUAL

ANother way is to use an unique id like this to the end of the url:

$('#scene_container').load('scene.html?uid'+uniqueId());
发布评论

评论列表(0)

  1. 暂无评论