// JavaScript Document
function ajaxSubmit(){
    //获取用户输入
    var title=document.forms[0].title.value;
    var author=document.forms[0].author.value;
    var content=document.forms[0].content.value;
    //创建XMLHttpRequest对象
	if(title==""||author==""||content=="")
	{
		var msg=document.getElementById("msg");
   
    //填充留言内容
    msg.innerHTML="please enter";
	return;
	}
    var xmlhttp;
    try{
        xmlhttp=new XMLHttpRequest();
    }catch(e){
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    //创建请求结果处理程序
    xmlhttp.onreadystatechange=function(){
        if (4==xmlhttp.readyState){
            if (200==xmlhttp.status){
                var date=xmlhttp.responseText;
                addToList(date);
            }else{
                alert("error");
            }
        }
    }
    //打开连接，true表示异步提交
    xmlhttp.open("post", "myemail.asp", true);
    //当方法为post时需要如下设置http头
    xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    //发送数据
    xmlhttp.send("title="+escape(title)+"&author="+escape(author)+"&content="+escape(content));
}

//将用户输入显示到页面
function addToList(date){
    //获取留言列表div容器
    var msg=document.getElementById("msg");
   
    //填充留言内容
    msg.innerHTML=date;
    //清空用户输入框
    document.forms[0].title.value="";
    document.forms[0].author.value="";
    document.forms[0].content.value="";
	alert(date);
}
