Implementation method and function of URL timestamp

Function: The time is appended at the end of the URL. This ensures that the request is not cached the first time it is sent, but is recreated and resent every time this method is called; the URL will be slightly different due to the timestamp. This technique is often used to ensure that a POST to a script actually generates a new request each time and that the web server does not try to cache the response from the server.

Implementation

//解决浏览器缓存
function timestamp(url)
{
    var getTimestamp=Math.random();
    var getTimestamp=new Date().getTime();
    if(url.indexOf("?")>-1)
    {
        url=url+"×tamp="+getTimestamp
    }
    else
    {
        url=url+"?timestamp="+getTimestamp
    }
     return url;
}

Guess you like

Origin blog.csdn.net/qq_40833062/article/details/129278757