URL完全相同时,浏览器可能直接从缓存中取结果数据。因此,可以添加无效查询参数,防止浏览器查缓存。
<div class="col-sm-4">
<img th:src="@{/kaptcha}" id="kaptcha" style="width:100px;height:40px;" class="mr-2"/>
<a href="javascript:refresh_kaptcha();" class="font-size-12 align-bottom">刷新验证码</a>
</div>
javascript
<script th:src="@{/js/global.js}"></script>
<!--jquery请求-->
<script>
function refresh_kaptcha() {
/*?p善意的欺骗浏览器路径改变了,其实实际访问路径没有改变 */
var path = CONTEXT_PATH + "/kaptcha?p=" + Math.random();
/*修改id为kaptcha的src属性值*/
$("#kaptcha").attr("src", path);
}
</script>