Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/03/2015, 20:21
nattadsa
 
Fecha de Ingreso: marzo-2014
Mensajes: 22
Antigüedad: 10 años, 1 mes
Puntos: 0
Pregunta hacer que llegue una Notificación sonora con ajax y php

Hola quiero que siempre al recibir una nueva entrada en la base de datos suene un sonido.

no estoy consiguiendo...alguien me ayuda? Alguna idea de como hacer? Desde ya gracias

index.php

Código:
<script src="<?php echo WWW . DS; ?>admin/js/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
function Ajax() {
var xmlHttp;
try {
xmlHttp = new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("No AJAX!?");
return false;
}
}
}

xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
document.getElementById('ReloadThis').innerHTML = xmlHttp.responseText;
setTimeout('Ajax()', 10);
}
}
xmlHttp.open("GET", "index.php?controller=Reserva&action=refresh", true); // aqui configuramos o arquivo
xmlHttp.send(null);
}

window.onload = function () {
setTimeout('Ajax()', 500); // aqui o tempo entre uma atualização e outra
};
</script>
</head>
<body>
<!-- barra TOP -->
<div id="top-bar">

<div class="page-full-width cf">

<ul id="nav" class="fl">

<li class="v-sep round button dark menu-user image-left">Usuário: <strong style="text-transform: uppercase;"><?php echo $_SESSION['login']['clientelogin'] ?></strong>
<!--<ul>
<li><a href="#">Perfil</a></li>
<li><a href="#">Herramientas</a></li>
<li><a href="#">Cambiar password</a></li>
<li><a href="#">Salir</a></li>
</ul> -->
</li>
<li class="notificacion-li" id="ReloadThis">

</li>
<li><a href="?controller=Cliente&action=logout" class="round button dark menu-logoff image-left">Salir</a></li>

</ul> <!-- fin nav -->

refresh.php

Código:
<script>
var sonido;
sonido = document.getElementById("sonido").value;
var cantidadVieja = 0;
var cantidadNueva = sonido;
if (cantidadNueva > cantidadVieja) {
cantidadVieja = cantidadNueva;
cantidadNueva = 0;
notificacionSonido.play();
}
</script>
<?php $numeroNotificaciones = $this->Numnotificaciones[0]['numnotificaciones'] ?>
<input id="sonido" type="hidden" value="<?php echo $numeroNotificaciones ?>">
<audio id="notificacionSonido">
<source src="<?php echo WWW . DS; ?>usuario/audio/notificacion.mp3" type="audio/mp3">
</audio>
<a href="#" class="round button dark menu-email-special image-left"><span style="display: inline; background-color: rgb(245, 108, 126);" class="notificacion-circulo"><?php echo $numeroNotificaciones; ?></span><span style="padding-left:1em;"> <?php
if ($numeroNotificaciones == 1) {
echo "Notificación nueva";
} else {
echo "Notificaciones nuevas";
}
?></span></a>
<ul>
<?php foreach ($this->notificaciones as $linha) : ?>
<li><a href="index.php?controller=Reserva&action=editarClub&cod_reserva=<?php echo $linha['reserva_cod'] ?>&cod_notif=<?php echo $linha['cod_notificaciones'] ?>"><b><?php echo $linha['nombrecliente']; ?></b> Solicitó reservar <b> <?php echo $linha['nombrecancha']; ?></b> </a></li>
<?php endforeach; ?>
</ul>