2016-05-15 52 views
0

我在phpMyAdmin id调用中有一列获取整数值1或0.当用户1进入该站点时,显示一个提醒('Welcome!');如何做到这一点,当用户点击确定将msg更新为0?更新数据库中的数据时什么时候出现提示

的index.html

<!DOCTYPE html> 
<html> 
<body> 

<h1>Getting server updates</h1> 
<div id="result"></div> 

<script> 
if(typeof(EventSource) !== "undefined") { 
    var source = new EventSource("demo_sse.php"); 

    source.onmessage = function(event) { 
     var msg = event.data; 
     if (msg>0){  
     alert('Welcome'); 
     }; 
    }; 
}; 
</script> 

</body> 
</html> 

demo_sse.php

<?php 

$dominio = "127.0.0.1"; 
$host = "localhost"; 
$user = "root"; 
$pass = ""; 
$banco = "teste"; 
$codificacao = 'utf8'; 

$conexao = mysqli_connect($host, $user, $pass, $banco) or die(mysqli_connect_error()); 

$sql= "select * from `msg`"; 

$resultado = mysqli_query($conexao,$sql); 
$tabela = mysqli_fetch_array($resultado); 
$id=$tabela['id']; 


header('Content-Type: text/event-stream'); 
header('Cache-Control: no-cache'); 

$time = date('r'); 
echo "data:{$id}\n\n"; 
flush(); 

?> 
+0

你应该澄清你的问题是什么,并提供一些代码说明你正在尝试做什么以及你在哪里遇到问题。 – fvgs

回答

0

你必须创建一个PHP脚本,该记录切换到0,然后用点击的情况下,确定按钮来触发对该脚本的Ajax请求。 Ajax将运行你的PHP并提供你想要的效果。如果你需要更多的指导,我可以做一个详细的例子,当我到电脑。

+0

知道了!你会告诉我一个例子吗?因为我对Ajax仍然陌生 –

相关问题