Home > Backend Development > PHP Tutorial > getElementsByTagName有关问题求解

getElementsByTagName有关问题求解

WBOY
Release: 2016-06-13 12:48:23
Original
920 people have browsed it

getElementsByTagName问题求解

<html><br />
<head><br />
<br />
<?php<br />
	$username=$_GET['username'];<br />
	$username=trim($username);//去掉空格<br />
	session_start();<br />
	$loginuser=$_SESSION['loginuser'];<br />
?><br />
<br />
<meta http-equiv="content-type" content="text/html;charset=utf-8"/><br />
<script src="my.js"></script><br />
<script><br />
	window.resizeTo(500,400);<br />
<br />
<br />
	window.setInterval("getMessage()",5000);<br />
	<br />
	function getMessage(){	<br />
		var myXmlHttpRequest=getXmlHttpObject();<br />
		if(myXmlHttpRequest){	<br />
			var url="GetMessageControl.php";<br />
			var data="getter=<?php echo $loginuser; ?>&sender=<?php echo $username; ?>";<br />
			myXmlHttpRequest.open("post",url,true);<br />
			myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");<br />
			//重点。指定处理结果的 函数<br />
			myXmlHttpRequest.onreadystatechange=function (){<br />
				if(myXmlHttpRequest.readyState==4){<br />
					if(myXmlHttpRequest.status==200){<br />
						var mesRes=myXmlHttpRequest.responseXML;<br />
						var cons=mesRes.getElementsByTagName("con");<br />
						var sendTimes=mesRes.getElementsByTagName("sendTime");<br />
						window.alert(cons.length);<br />
						if(cons.length!=0){<br />
							for(var i=0;i<cons.length;i++){<br />
								$('mycons').value+="<?php echo $username; ?>对<?php echo $loginuser; ?>说:"+cons[i].childNodes[0].nodeValue+" "+sendTimes[i].childNodes[0].nodeValue; <br />
							<br />
							}<br />
						}<br />
					}<br />
				}<br />
			<br />
			}<br />
			myXmlHttpRequest.send(data);<br />
<br />
<br />
		}<br />
	<br />
	}<br />
<br />
<br />
<br />
	function sendMessage(){<br />
		var myXmlHttpRequest=getXmlHttpObject();<br />
<br />
		if(myXmlHttpRequest){<br />
			var url="SendMessageControl.php";<br />
			//js中使用php数据<br />
			var data="con="+$('con').value+"&getter=<?php echo $username; ?>&sender=<?php echo $loginuser; ?>";<br />
			window.alert(data);<br />
		<br />
			myXmlHttpRequest.open("post",url,true);<br />
			myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");<br />
			myXmlHttpRequest.onreadystatechange=function (){<br />
				if(myXmlHttpRequest.readyState==4){<br />
					if(myXmlHttpRequest.status==200){<br />
						<br />
					}<br />
				}<br />
			<br />
			}<br />
			myXmlHttpRequest.send(data);<br />
		}<br />
	<br />
	}<br />
</script><br />
</head><br />
<br />
<br />
<br />
<center><br />
<h1>聊天室(您正在和<font color="red"><?php echo $username; ?></font>聊天)</h1><br />
	<textarea cols="30" rows="10" id="mycons"></textarea><br><br />
	<input type="text" style="width:200px" id="con"><br />
	<input type="button" value="send" onclick="sendMessage()"><br />
<br />
<br />
<br />
</center><br />
<br />
</html><br />
Copy after login




<?php <br />
	include 'SqlHelper.class.php';<br>
<br>
<br>
	class MessageService{<br>
		//将数据信息添加到数据库<br>
		function addMessage($sender,$getter,$con){<br>
			$sql="insert into message (sender,getter,content,sendTime) values('$sender','$getter','$con',now())";<br>
			<br>
		//	file_put_contents("d:/test.txt","sql=".$sql."\r\n",FILE_APPEND);	<br>
	<br>
			$sqlHelper=new SqlHelper();<br>
			return $sqlHelper->execute_dml($sql);<br>
			<br>
			<br>
		<br>
		}<br>
		//获取信息,并把数据组装好返回给客户端(聊天室)<br>
		function getMessage($getter,$sender){<br>
			$sql="select * from message where getter='$getter' and sender='$sender' and isGet=0";<br>
		<br>
<br>
			$sqlHelper=new SqlHelper(); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template