首页 >后端开发 >php教程 > PHP中遇到AJAX的有关问题

PHP中遇到AJAX的有关问题

WBOY
WBOY原创
2016-06-13 12:35:16835浏览

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 />
}

不知道为什么,这个responseText返回的是一大面的html代码.

php?ajax? php ajax
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn