本篇文章給大家分享的是有關(guān)jquery php怎么實(shí)現(xiàn)實(shí)時(shí)數(shù)據(jù)更新,小編覺(jué)得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說(shuō),跟著小編一起來(lái)看看吧。
10年積累的成都網(wǎng)站制作、網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)制作后付款的網(wǎng)站建設(shè)流程,更有平武免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
本文操作環(huán)境:Windows7系統(tǒng)、PHP7.1版、Dell G3電腦。
jquery php如何實(shí)現(xiàn)實(shí)時(shí)數(shù)據(jù)更新?
php+jQuery ajax實(shí)現(xiàn)的實(shí)時(shí)刷新顯示數(shù)據(jù)功能示例
具體如下:
創(chuàng)建數(shù)據(jù)表:demo
-- -- 表的結(jié)構(gòu) `demo` -- CREATE TABLE IF NOT EXISTS `demo` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) COLLATE utf8_bin NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=5 ; -- -- 轉(zhuǎn)存表中的數(shù)據(jù) `demo` -- INSERT INTO `demo` (`id`, `name`) VALUES (1, '雷軍'), (2, '馬化騰'), (3, '李彥宏'), (4, '馬云');
服務(wù)器文件:demo.php
<?php $MySQLi = new mysqli("localhost","root","","test"); $mysqli->set_charset('utf8'); $query = 'SELECT * FROM demo'; $result = $mysqli->query($query); $arr = $result->fetch_all(MYSQLI_ASSOC); $info = json_encode($arr); echo $json = '{"success":true,"info":'.$info.'}';
顯示數(shù)據(jù)網(wǎng)頁(yè): fresh.html
<html> <head> <meta charset='utf-8'> <title>hello</title> </head> <body> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script> function check(){ $.ajax({ type:"GET", url:"./demo.php", dataType:"json", success:function(data){ if(data.success){ var count = data.info.length; for(i=0;i<count;i++){ var dom = "<tr align='center' id='"+data.info[i].id+"'><td>"+data.info[i].id+"</td><td>"+data.info[i].name+"</td></tr>"; var tag = '#'+data.info[i].id; if(!$(tag).length){ $("#info").append(dom); } } }else{ alert('error'); } }, error:function(res){ alert(res.status); } }); } window.setInterval(check, 1000); //每秒執(zhí)行一次 </script> <body> <div style='width:600px;margin:0 auto;'> <table border='1' width="600px"> <thead> <tr><th>id</th><th>name</th></tr> </thead> <tbody id='info'> <tr align='center' id='111'><td>111</td><td>測(cè)試</td></tr> </tbody> </table> </div> </body> </html>
以上就是jquery php怎么實(shí)現(xiàn)實(shí)時(shí)數(shù)據(jù)更新,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見(jiàn)到或用到的。希望你能通過(guò)這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當(dāng)前文章:jqueryphp怎么實(shí)現(xiàn)實(shí)時(shí)數(shù)據(jù)更新
網(wǎng)站路徑:http://sd-ha.com/article40/ghdpeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、商城網(wǎng)站、軟件開(kāi)發(fā)、網(wǎng)站改版、網(wǎng)站制作、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)