function getCaptcha(){
var xhr = new XMLHttpRequest()
xhr.responseType = 'blob';
xhr.open('get', Constant.openfrontCaptchaUrl+"?"+new Date().getTime(), true)
var jwtToken=$.cookie(Constant.tokenCookieKey);
if(!Utils.isEmpty(jwtToken)){
xhr.setRequestHeader(Constant.tokenHeaderKey,jwtToken);
}
xhr.onreadystatechange = e => {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
$('#captcha_img').get(0).src = URL.createObjectURL(xhr.response);
$('#captcha_img').get(0).onload = () => {
URL.revokeObjectURL($('#captcha_img').get(0).src);
}
}
};
xhr.send(null);
}
getCaptcha();
$('#captcha_img').click(function() {
getCaptcha();
})
<img>设置header
于 2022-10-10 09:56:17 首次发布