直接使用ajax直接获取验证码的照片是不行的,下面是正确代码:
function getCaptcha() {
var uri = "../photo/captcha";
var xhr = new XMLHttpRequest();
xhr.open("get", uri, true);
xhr.responseType = "blob";
xhr.onload = function() {
if(this.status == 200) {
var blob = this.response;
//var img = document.createElement("img");
var img = document.getElementById("img_captcha");
/*img.onload = function(e) {
window.URL.revokeObjectURL(img.src);
};*/
img.src = window.URL.createObjectURL(blob);
//$("#imgcontainer").html(img);
}
}
xhr.send();
}