function SendMsg() { var text = document.getElementById("text"); if (text.value == "" || text.value == null) { alert("发送信息为空,请输入!") } else { AddMsg('default', SendMsgDispose(text.value)); const xhr = new XMLHttpRequest(); xhr.open('GET', "http://www.365jqr.com/index.html?question="+text.value); xhr.responseType = 'text'; // 文件类型设置成blob xhr.setRequestHeader("Content-type","application/xml;charset=gb2312"); xhr.send(); xhr.onreadystatechange = function () { //readyState: //0: 请求未初始化 //1: 服务器连接已建立 //2: 请求已接收 //3: 请求处理中 //4: 请求已完成,且响应已就绪 //status: //200: 'ok' //404: 未找到页面或接口 //xhr.responseText: 后端返回的数据 if(xhr.readyState == 4 && xhr.status == 200 ) { AddMsg('rotbot', SendMsgDispose(xhr.responseText)); //alert(document.documentElement.clientHeight); //alert(document.body.scrollHeight); if ((document.body.scrollHeight-document.documentElement.clientHeight-150)>0) { window.scrollTo(0, document.body.scrollHeight); } } } text.value=""; } } // 发送的信息处理 function SendMsgDispose(detail) { detail = detail.replaceAll("<00>", "
").replaceAll(" ", " ") //detail = detail.replace("\n", "
").replace(" ", " ") return detail; } // 增加信息 function AddMsg(user,content) { var str = CreadMsg(user, content); var msgs = document.getElementById("msgs"); msgs.innerHTML = msgs.innerHTML + str; } // 生成内容 function CreadMsg(user, content) { var str = ""; if(user == 'default') { str = "
" + content +"
" } else { str = "
" + content + "
"; } return str; }