我尝试使用服务器端事件来更新或添加数据库中的数据。在这种情况下,为什么index.html中的onmessage事件在我通过dataAdd.php向数据库添加数据后不起作用?
index.html:
<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
mysql_connect("localhost","username","password");
mysql_select_db("database");
mysql_query("set names utf8");
$result = mysql_query("select * from table order by id desc limit 1;");
$row = mysql_fetch_array($result);
echo "data: $row[message]";
flush();
?>
sse.php:
<?php
mysql_connect("localhost","username","password");
mysql_select_db("database");
mysql_query("set names utf8");
if(isset($_GET['text'])) {
mysql_query("insert into chat (message) values ('$_GET[text]')");
}
?>
dataAdd.php:
www.b.com/xyz.php?id=23 to www.a.com/xyz.php?id=23