local-host 2008-10-03 21:23 采纳率: 100%
浏览 315
已采纳

停止 jQuery。 缓存的负载响应

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

$('#searchButton').click(function() {
    $('#inquiry').load('/portal/?f=searchBilling&pid=' + $('#query').val());            
});

But the returned result is not always reflected. For example, I made a change in the response that spit out a stack trace but the stack trace did not appear when I clicked on the search button. I looked at the underlying PHP code that controls the ajax response and it had the correct code and visiting the page directly showed the correct result but the output returned by .load was old.

If I close the browser and reopen it it works once and then starts to return the stale information. Can I control this by jQuery or do I need to have my PHP script output headers to control caching?

转载于:https://stackoverflow.com/questions/168963/stop-jquery-load-response-from-being-cached

  • 写回答

14条回答 默认 最新

  • 衫裤跑路 2008-10-03 21:26
    关注

    You have to use a more complex function like $.ajax() if you want to control caching on a per-request basis. Or, if you just want to turn it off for everything, put this at the top of your script:

    $.ajaxSetup ({
        // Disable caching of AJAX responses
        cache: false
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(13条)

报告相同问题?