parent
71be85b656
commit
d339f2d5c7
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
$con = mysqli_connect("192.168.136.129", "root", "1213800", "webData");
|
||||
if (!$con) {
|
||||
die('Could not connect: ' . mysqli_error($con));
|
||||
}
|
||||
// 设置编码,防止中文乱码
|
||||
mysqli_set_charset($con, "utf8");
|
||||
$cid = $_POST['cid'];
|
||||
$topic = $_POST['topic'];
|
||||
$content = $_POST['content'];
|
||||
$sql="INSERT INTO Feedback (cid, topic, content)
|
||||
VALUES
|
||||
('$cid','$topic','$content')";
|
||||
|
||||
$result = mysqli_query($con, $sql);
|
||||
mysqli_close($con);
|
||||
echo 'OK';
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
$hostname = "192.168.136.129";
|
||||
$username = "root";
|
||||
$password = "1213800";
|
||||
$database = "webData";
|
||||
$con = mysqli_connect($hostname, $username, $password, $database);
|
||||
if (!$con)
|
||||
{
|
||||
die('Could not connect: ' . mysqli_error($con));
|
||||
}
|
||||
// 设置编码,防止中文乱码
|
||||
mysqli_set_charset($con, "utf8");
|
||||
|
||||
$sql="select * from Tips order by rand() limit 5";
|
||||
|
||||
$result = mysqli_query($con,$sql);
|
||||
|
||||
$tips = array();
|
||||
|
||||
while($tip = mysqli_fetch_array($result, MYSQLI_ASSOC))
|
||||
{
|
||||
$tips[] = $tip;
|
||||
}
|
||||
|
||||
class Response {
|
||||
public static function xml($code, $message = '', $data = []){
|
||||
|
||||
# 判断参数有效性及错误处理
|
||||
// code...
|
||||
|
||||
# 结果(最终数组)
|
||||
$xmlResult = [
|
||||
"code" => $code,
|
||||
"message" => $message,
|
||||
"data" => $data
|
||||
];
|
||||
|
||||
# 更改头部(为了更清晰的展示XML节点)
|
||||
header('Content-type: text/xml');//xml
|
||||
|
||||
# 生成XML(字符串拼接方式)
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?>';//xml head
|
||||
$xml .= '<root>';//拼接根节点(开始)
|
||||
|
||||
$xml .= self::toXML($xmlResult);//调用处理函数
|
||||
|
||||
$xml .= '</root>';//拼接根节点(结束)
|
||||
echo $xml;
|
||||
}
|
||||
|
||||
# 解析结果数组转为对应的xml节点
|
||||
public static function toXML($data){//参数为data(result)
|
||||
|
||||
# 临时存储xml数据
|
||||
$xml = $id = '';
|
||||
|
||||
# 遍历并拼接字符串
|
||||
foreach($data as $key => $value){
|
||||
|
||||
# 如果key是数字(即非关联数组 => [hello,2,true] )
|
||||
# 以 <item id='?'></item> 展示,id为key
|
||||
if(is_numeric($key)){//如果是数字
|
||||
$id = "id='{$key}'";//将key作为id属性
|
||||
$key = 'item ';//将item作为节点名
|
||||
}
|
||||
|
||||
$xml .= "<{$key}{$id}>";//开始节点
|
||||
|
||||
# 如果是数组则递归(否则直接返回value值)
|
||||
$xml .= is_array($value) ? self::toXML($value) : $value;
|
||||
|
||||
$xml .= "</{$key}>";//结束节点
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
|
||||
# 调用
|
||||
Response::xml(200, '返回成功', $tips);
|
||||
mysqli_free_result($result);
|
||||
mysqli_close($con);
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
$con = mysqli_connect("192.168.136.129","root","1213800", "computer_accessories");
|
||||
if (!$con)
|
||||
{
|
||||
die('Could not connect: ' . mysqli_error($con));
|
||||
}
|
||||
// 设置编码,防止中文乱码
|
||||
mysqli_set_charset($con, "utf8");
|
||||
$sql="select * from trendings order by frequency desc limit 3;";
|
||||
|
||||
$result = mysqli_query($con,$sql);
|
||||
|
||||
$recLists = array();
|
||||
while($rec = mysqli_fetch_array($result, MYSQLI_ASSOC))
|
||||
{
|
||||
$recLists[] = $rec;
|
||||
}
|
||||
$recDict = json_encode($recLists);
|
||||
echo $recDict;
|
@ -0,0 +1,25 @@
|
||||
function submitFeedback() {
|
||||
console.log("enter submitFeedback!!!");
|
||||
let cid = document.getElementById('u165_input').value; //联系方式
|
||||
let topic = document.getElementById('u167_input').value; //留言主题
|
||||
let content = document.getElementById('u166_input').value; //留言内容
|
||||
if (topic==="" || content==="")
|
||||
alert("请先填写所有信息再提交(联系方式选填)!")
|
||||
else if (confirm("是否确认提交留言?")===true){
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "controllers/contactController.php",
|
||||
data: {'cid' : cid, 'topic': topic, 'content': content},
|
||||
success: function (msg){
|
||||
if (msg==='OK'){
|
||||
let sucButton = document.getElementById('u169');
|
||||
sucButton.style["display"]="inherit"
|
||||
sucButton.style["visibility"]="visible";
|
||||
alert("留言成功!");
|
||||
}
|
||||
else
|
||||
alert("留言未成功,请重新提交一遍..qwq");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
function flushTip() {
|
||||
console.log("enter flushTip!!!");
|
||||
if (window.XMLHttpRequest) {
|
||||
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
} else {
|
||||
// IE6, IE5 浏览器执行代码
|
||||
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
xmlhttp.onreadystatechange = function () {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
const tipsXML = xmlhttp.responseXML;
|
||||
let tip0 = tipsXML.getElementById("0").getElementsByTagName("text")[0].innerHTML;
|
||||
document.getElementById("u72_text").innerHTML = tip0;
|
||||
let tip1 = tipsXML.getElementById("1").getElementsByTagName("text")[0].innerHTML;
|
||||
document.getElementById("u77_text").innerHTML = tip1;
|
||||
let tip2 = tipsXML.getElementById("2").getElementsByTagName("text")[0].innerHTML;
|
||||
document.getElementById("u82_text").innerHTML = tip2;
|
||||
let tip3 = tipsXML.getElementById("3").getElementsByTagName("text")[0].innerHTML;
|
||||
document.getElementById("u87_text").innerHTML = tip3;
|
||||
let tip4 = tipsXML.getElementById("4").getElementsByTagName("text")[0].innerHTML;
|
||||
document.getElementById("u92_text").innerHTML = tip4;
|
||||
}
|
||||
};
|
||||
xmlhttp.open("GET", "controllers/tipsController.php", true);
|
||||
xmlhttp.send();
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue