prevent xmlHttpReq 's browser caching

前端 未结 1 2207
小鲜肉
小鲜肉 2021-02-20 04:07

It seems that all the browsers other than Opera cache XHR requests in my Javascript program. The URL in the XHR request refers to a CGI program on the server which generates a d

1条回答
  •  天涯浪人
    2021-02-20 04:47

    For every AJAX request you make, generate a unique value and add it to the ajax URL as a query parameter:

    /example/url/post.php?rand=09809807896768
    

    I use to generate the current unix timestamp in JS and use that - this ensures I do not get duplicated stamps.

    That way every request is unique and will not get cached. This is a simple but fairly common AJAX trick - usually fixing IE and testing issues.

    If you were to use jQuery, it does this for you by setting the property cache to false on the AJAX settings.

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