Stop jQuery .load response from being cached

前端 未结 14 1885
迷失自我
迷失自我 2020-11-22 03:54

I have the following code making a GET request on a URL:

$(\'#searchButton\').click(function() {
    $(\'#inquiry\').load(\'/portal/?f=searchBilling&pid=         


        
相关标签:
14条回答
  • 2020-11-22 05:01

    Another approach to put the below line only when require to get data from server,Append the below line along with your ajax url.

    '?_='+Math.round(Math.random()*10000)

    0 讨论(0)
  • 2020-11-22 05:01

    Do NOT use timestamp to make an unique URL as for every page you visit is cached in DOM by jquery mobile and you soon run into trouble of running out of memory on mobiles.

    $jqm(document).bind('pagebeforeload', function(event, data) {
        var url = data.url;
        var savePageInDOM = true;
    
        if (url.toLowerCase().indexOf("vacancies") >= 0) {
            savePageInDOM = false;
        }
    
        $jqm.mobile.cache =  savePageInDOM;
    })
    

    This code activates before page is loaded, you can use url.indexOf() to determine if the URL is the one you want to cache or not and set the cache parameter accordingly.

    Do not use window.location = ""; to change URL otherwise you will navigate to the address and pagebeforeload will not fire. In order to get around this problem simply use window.location.hash = "";

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