PHP中遇到AJAX的问题
<?php<br /> header("Content-Type:html/text;Charset=utf-8");<br /> $name = $_POST['name'];<br /> $email = $_POST['email'];<br /> $comment = $_POST['comment'];<br /> $fh = @fopen("14-6.txt","ab");<br /> fwrite($fh,"姓名:".$name,strlen($name));<br /> fwrite($fh,"email:".$email,strlen($email));<br /> fwrite($fh,"评论:".$comment,strlen($comment));<br /> fclose($fh);<br /> echo 1;<br /> ?>
function $(id){<br /> return document.getElementById(id);<br /> }<br /> function addcomment(){<br /> var url = "14-6.php";<br /> var status = document.getElementById("divmsg");<br /> status.value="正在提交》》》";<br /> var param = "name="+$("name").value+"email="+$("email").value+"comment="+$("comment").value;<br /> xmlhttp_request.onreadystatechange = function(){<br /> if(xmlhttp_request.readyState==4 && xmlhttp_request.status == 200){//相应完全显示信息<br /> alert (xmlhttp_request.responseText);<br /> if(xmlhttp_request.responseText == "1"){<br /> status.value = "发表成功!!";<br /> $("name").value="";<br /> $("email").value="";<br /> $("comment").value="";<br /> }else{<br /> status.value = "发表失败!请重新发表!";<br /> }<br /> } <br /> }<br /> xmlhttp_request.open("POST",url,true);<br /> xmlhttp_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//设置头信息<br /> xmlhttp_request.send(param);<br /> }