前辈们:小弟现在使用Ajax制作局部刷新验证码,在获取服务端发送过来的图像流的时候出现问题了,关键代码代码如下:
这里是Ajax需要用的JavaScript:
function createXMLRequset(){ if(window.XMLHttpRequest){ XMLHttp = new XMLHttpRequest(); }else if(window.ActiveObject){ XMLHttp = new ActiveObject("Microsoft.XMLHTTP"); }}function doAjax(){ createXMLRequset(); XMLHttp.open("POST","initLogin.action",true); XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); XMLHttp.onreadystatechange = p; XMLHttp.send(null);}function p(){ if(XMLHttp.readyState == 4){ if(XMLHttp.status == 200){ var str = XMLHttp.responseText; document.getElementById("init").src=str; } }}public String initLogin(){ RandomNumUtil randomNumUtil = RandomNumUtil.Instance(); this.setInputStream(randomNumUtil.getImage()); ActionContext.getContext().getSession().put("random", randomNumUtil.getString()); return SUCCESS; }function p(){ if(XMLHttp.readyState == 4){ if(XMLHttp.status == 200){ var str = XMLHttp.responseText; document.getElementById("init").src=str; }}