Home >Backend Development >PHP Tutorial >PHP中遇到AJAX的有关问题

PHP中遇到AJAX的有关问题

WBOY
WBOYOriginal
2016-06-13 11:38:06757browse

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
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn