xhr.onreadystatechange=function (){
if(xhr.readyState == 4 && xhr.status == 200){
//txt为map的JSON串
var txt = xhr.responseText;
//解析json得到map对象
var obj =JSON.parse(txt);
//遍历map对象获得key value
for(var i in obj){
//错误信息
//拿到代表对错的img标签
var emailnameresultimg = document.getElementById('emailnameresultimg');
//图片路径之前传过来的是带狗皮膏药的全部路径,但是解析后用不了,就直接传图片名字过来了,将图片名字拼接到已经写好的字符串后面
emailnameresultimg.src="${pageContext.request.contextPath}/dangdang/images/"+i;
if(obj[i] == "正确"){
//获取sapn标签
document.getElementById('emailinfo').innerHTML=obj[i];
//设置span标签的文本颜色
document.getElementById('emailinfo').style="color:#666";
}else{
document.getElementById('emailinfo').innerHTML=obj[i];
document.getElementById('emailinfo').style="color:red";
}
}
}
}。