防止浏览器对url请求的缓存

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_22701869/article/details/82454507

有时候发送请求,浏览器会直接读取缓存数据,不会去请求后台数据,比如http://localhost:8080/test/login/index,请求一次之后,再次发送请求的时候,由于url请求没有发生变化,浏览器会自动读取缓存。这一点会给开发带来一些麻烦。

解决办法:在请求后面加上一个随机数,这样每次发送的都是不一样的请求

url = "http://localhost:8080/test/login/index"?r=Math.random();

猜你喜欢

转载自blog.csdn.net/qq_22701869/article/details/82454507