日期:2014-05-16 浏览次数:20827 次
<script type="text/javascript">
/*通过异步传输XMLHTTP发送参数到ajaxServlet,返回符合条件的XML文档*/
var req=null;
function getResult() {
var message=document.getElementById('message');
var sendstr;
var url="http://127.0.0.1:8080/WebService/servlet/AjaxServlet?time="+new Date().toString();
if(message==null){
sendstr="";
alert("为空");
}else{
sendstr = "sendmsg=" + message.value;
alert("不为空");
}
if(window.ActiveXObject)
{
req = new ActiveXObject('Microsoft.XMLHTTP');
}
else if(window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
if (req) {
req.onreadystatechange = complete;
req.open("POST", url);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(sendstr);
}
}
function complete() {
if (req.readyState == 4) {
if (req.status==200) {
var v = req.responseText;
showmsg(v);
}
if(req.status==0){
alert("抱歉,留言功能不支持360浏览器");
}
}
}
function showmsg(v){
var values=v.split("===");
for(var i=0;i<values.length;i++){
alert("留言提交成功");
if(values[i]!=null){
var values2=values[i].split("==");
document.getElementById("message"+(i+1)).innerHTML=values2[0];
document.getElementById("time"+(i+1)).innerHTML=values2[1];
}
}
}
window.onload=getResult();
</script>