Alerte lors d'une insertion, à la "Facebook"
Bonjour à tous.
Je suis en train d'essayer de réaliser un système d'alerte, comme Facebook, où, lorsque je poste une info sur une page admin, mes clients sont prévenu en étant sur une page qu'ils affichent tout le temps sur leur navigateur.
J'ai donc installer Xampp, j'ai crée une base Mysql nommée alerte, et j'ai crée une table :
Code:
1 2 3 4 5 6
| CREATE TABLE IF NOT EXISTS `messageTest` (
`id` int(50) NOT NULL AUTO_INCREMENT,
`notification` varchar(255) NOT NULL,
`status` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; |
puis dans htdocs, création d'un dossier alerte, contenant index.php avec :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document sans titre</title>
<style>
#notification_count
{
padding: 0px 3px 3px 7px;
background: #cc0000;
color: #ffffff;
font-weight: bold;
margin-left: 77px;
border-radius: 9px;
-moz-border-radius: 9px;
-webkit-border-radius: 9px;
position: absolute;
margin-top: -1px;
font-size: 10px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
function addmsg(type, msg){
$('#notification_count').html(msg);
}
function waitForMsg(){
$.ajax({
type: "GET",
url: "select.php",
async: true,
cache: false,
timeout:50000,
success: function(data){
addmsg("new", data);
setTimeout(
waitForMsg,
1000
);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
addmsg("error", textStatus + " (" + errorThrown + ")");
setTimeout(
waitForMsg,
15000);
}
});
};
$(document).ready(function(){
waitForMsg();
});
</script>
</head>
<body>
<span id="notification_count"></span>
<a href="#" id="notificationLink" onclick = "return getNotification()">Notifications</a>
<div id="HTMLnoti" style="textalign:center"></div>
</body>
</html> |
et dans select.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <?php
$servername = "localhost";
$username = "root";
$password = "monmotdepasse";
$dbname = "alerte";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * from messageTest where status = 'unread'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$count = $result->num_rows;
echo $count;
$conn->close();
?> |
Mais sur ma page s'affiche "parsererror (undefined)" à la place du compteur.
Une idée de l'erreur ?
Merci à tous :-)