index.php
<?php include_once("class/Class_Mysql.php"); include_once("conf/autoload.php"); $MYSQL=new php_mysql(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DATA,"conn",MYSQL_CODE); session_start(); if(isset($_GET['Action'])&&$_GET['Action']!="") $Action=$_GET['Action']; else $Action="default"; switch($Action) { case "default": include_once("Mode/Chat/index.php"); default: } ?>
autolaod.php
<?php include_once("mysql.php"); ?>
mysql.php
<?php //定义数据库连接配置 define(MYSQL_HOST,"localhost"); define(MYSQL_USER,"root"); define(MYSQL_PASS,"*********"); define(MYSQL_DATA,"test1"); define(MYSQL_CODE,"utf8"); ?>
Get.php
<?php $sql="select * from Chat"; $MYSQL->query($sql); while ($temp=$MYSQL->fetch_array()) { //$data.=sprintf("<tr><td width=\"20%%\">%s</td><td width=\"60%%\">%s</td><td width=\"20%%\">%s</td></tr>",$temp['SendName'],$temp['SendText'],$temp['Time']); $data.=sprintf("<tr><td width=\"20%%\">%s</td><td width=\"60%%\">%s</td><td width=\"20%%\">%s</td></tr>",$temp['SendName'],$temp['SendText'],$temp['Time']); } echo json_encode($data); ?>
send.php
<?php $sql="select * from Chat"; $MYSQL->query($sql); while ($temp=$MYSQL->fetch_array()) { //$data.=sprintf("<tr><td width=\"20%%\">%s</td><td width=\"60%%\">%s</td><td width=\"20%%\">%s</td></tr>",$temp['SendName'],$temp['SendText'],$temp['Time']); $data.=sprintf("<tr><td width=\"20%%\">%s</td><td width=\"60%%\">%s</td><td width=\"20%%\">%s</td></tr>",$temp['SendName'],$temp['SendText'],$temp['Time']); } echo json_encode($data); ?>
Chat/index.php
<?php if(isset($_GET['Run'])&&$_GET['Run']!="") $Run=$_GET['Run']; else $Run="default"; switch($Run) { case "default": include_once("View/index.php"); break; case "SendChat": include_once("Fun/send.php"); break; case "GetChat": include_once("Fun/Get.php"); break; default: } ?>
Chat/View/index.php
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>2333</title> </head> <body> <script type="text/javascript" src="https://cdn.bootcss.com/canvas-nest.js/1.0.1/canvas-nest.min.js"></script> <div id="MainPage"> <div align="center"> <p>吐槽墙</p> </div> <div id="ChatTitle" align="center"> <table width="60%" border="1"> <tr><td width="20%">花名</td><td width="60%">吐槽</td><td width="20%">握爪时间</td></tr> </table> </div> <div id="ChatContent" align="center"> <table width="60%" border="1" id="ChatContentTable"> </table> </div> <div id="SendChat" align="center"> <textarea id="ChatText" style="width: 800px; height: 100px;"> </textarea> <br/><input type="button" value="留言" onclick="SendData()"> <!-- 配置文件 --> <script type="text/javascript" src="https://xty-1256352088.cos.ap-shanghai.myqcloud.com/ueditor/ueditor.config.js"></script> <!-- 编辑器源码文件 --> <script type="text/javascript" src="https://xty-1256352088.cos.ap-shanghai.myqcloud.com/ueditor/ueditor.all.js"></script> <!-- 实例化编辑器 --> <script type="text/javascript"> var ue = UE.getEditor('ChatText', { toolbars: [ ['fullscreen', 'source', 'undo', 'redo','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']] } ); GetChatData(); /*function SendData() { var Content=ue.getContent(); var xmlhttp; if(window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("POST","index.php?Action=default&Run=SendChat",false) xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("ContentTest="+Content); if(xmlhttp.readyState==4&&xmlhttp.status==200) { var data=eval("("+xmlhttp.responseText+")"); if(data=="OK")alert("留言成功!"); else alert("留言失败!"); GetChatData(); } }*/ function SendData() { //var Content; //Content=document.getElementById("ChatText").innerHTML; //console.log(Content); var Content=ue.getContent(); var xmlhttp; if(window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("POST","index.php?Action=default&Run=SendChat",false); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("ContentTest="+Content); if (xmlhttp.readyState==4&&xmlhttp.status==200) { var data=eval("("+xmlhttp.responseText+")"); if(data="OK")alert("success"); else alert("wrong"); GetChatData(); } } function GetChatData() { //<tr><td width="20%">xxx</td><td width="60%">xxxx</td><td width="20%">xxxx</td></tr> var xmlhttp; if(window.XMLHttpRequest) xmlhttp= new XMLHttpRequest(); else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("GET","index.php?Action=default&Run=GetChat",false); xmlhttp.send(); if(xmlhttp.readyState==4&&xmlhttp.status==200) { var data=eval("("+xmlhttp.responseText+")"); document.getElementById("ChatContentTable").innerHTML=data; } /*function GetChatData() { //<tr><td width="20%">xxx</td><td width="60%">xxxx</td><td width="20%">xxxx</td></tr> var xmlhttp; if(window.XMLHttpRequest) xmlhttp= new XMLHttpRequest(); else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("GET","index.php?Action=default&Run=GetChat",false); xmlhttp.send(); if(xmlhttp.readyState==4&&xmlhttp.status==200) { var data=eval("("+xmlhttp.responseText+")"); document.getElementById("ChatContentTable").innerHTML=data; } }*/ } </script> </div> </body> </html>
关于作者