日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

聊天系统

發(fā)布時(shí)間:2023/12/3 windows 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 聊天系统 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

顯示所有的信息

chat.html

<!DOCTYPE html><html> <head> <meta charset="UTF-8"><title></title><style>#button1{background:skyblue;border-radius:20px;width:100px;}</style><script>function showmessage(){var xhr=new XMLHttpRequest();xhr.open("GET","index.php?t="+new Date().getTime(),true);//xhr.send();xhr.onreadystatechange = function(){if(xhr.readyState==4){document.getElementById('div1').innerHTML = "";str = JSON.parse(xhr.responseText);console.log(str.length);var i=0;for(i;i<str.length;i++){document.getElementById('div1').innerHTML += str[i].receiver+"說(shuō):"+str[i].con+"<br>";}}}} showmessage(); window.onload = function(){setInterval("showmessage()",2000); }</script></head> <body> <button id="button1">點(diǎn)擊</button> <input id="input1"> <div id="div1"></div></body> <script type="text/javascript">var inp1=document.getElementById("input1");document.getElementById("button1").onclick=function(){alert(inp1.value);var username = username;var password = password;var xhr = new XMLHttpRequest();xhr.onreadystatechange = function(){if(xhr.readyState==4) {}}xhr.open("GET",send.php,true);xhr.send();}</script> </html>

index.php

<?php header("Content-type:application/json;charset=utf-8"); $link= mysqli_connect("localhost","root","");if(!$link){exit('數(shù)據(jù)庫(kù)連接失敗'); }mysqli_set_charset($link,'utf8');mysqli_select_db($link,'test');$sql = "SELECT * FROM `content` ";$obj = mysqli_query($link,$sql);while ($rows = mysqli_fetch_assoc($obj)){$info[] = $rows; }echo json_encode($info);

插入所有的信息

chat.html

<!DOCTYPE html><html> <head> <meta charset="UTF-8"><title></title><style>#button1{background:skyblue;border-radius:20px;width:100px;}</style></head> <body> <button id="button1">點(diǎn)擊</button> <input id="input1"> <input id="input2"> <div id="div1"></div></body> <script type="text/javascript">document.getElementById("button1").onclick=function(){var div1 = document.getElementById("div1");var inp1=document.getElementById("input1");var inp2=document.getElementById("input2");var username = inp1.value;var con = inp2.value;var xhr = new XMLHttpRequest();xhr.onreadystatechange = function(){if(xhr.readyState==4) {div1.innerHTML = xhr.responseText;}}xhr.open("GET","send.php?username="+username+"&con="+con,true);xhr.send();}</script> </html>

send.php

<?php $username = $_GET["username"]; $con = $_GET["con"];header("Content-type:application/json;charset=utf-8"); $link= mysqli_connect("localhost","root","");if(!$link){exit('數(shù)據(jù)庫(kù)連接失敗'); }mysqli_set_charset($link,'utf8'); mysqli_select_db($link,'test');$sql ="INSERT INTO `test`.`content` ( `receiver` , `con` ) VALUES ( '$username', '$con' ); ";$obj = mysqli_query($link,$sql);echo $username; echo $con;

總結(jié)

以上是生活随笔為你收集整理的聊天系统的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。