Bonjour � tous et � toute.
J'ai un petit script en ajax qui v�rifie dans ma bdd si j'ai une nouvelle commande toute les 20 secondes.
Si il y a une nouvelle commande (champ de table � 1) un bouton avec un lien vers mes commandes s'affiche.
J'aimerai aussi qu'un son retentisse pour �viter de devoir rester plant� devant l'�cran en attendant les commandes.
J'ai un petit script en js qui �met un son et j'aimerai le mettre dans la fonction ajax qui affiche le div mais je n'y arrive pas.
Je met mon script actuelle qui affiche la div et mon script js qui �met le son en esp�rant que quelqu'un puise m'aider.
Ajax qui demande � la page charger.php de v�rifier si il y a une nouvelle commande.
page charger.php qui va interroger la bdd pour voir si il y a une nouvelle commande.
Code : S�lectionner tout - Visualiser dans une fen�tre � part
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 function writeInDiv(text){ var objet = document.getElementById('div_nbr_commande'); objet.innerHTML = text; } function ajax_verif_commande() { var xhr_commande = null; if (window.XMLHttpRequest || window.ActiveXObject) { if (window.ActiveXObject) { try { xhr_commande = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { xhr_commande = new ActiveXObject("Microsoft.XMLHTTP"); } } else { xhr_commande = new XMLHttpRequest(); } } else { alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest..."); return null; } xhr_commande.open("GET", "http://mon-site/insert/charger.php", false); xhr_commande.send(null); writeInDiv(xhr_commande.responseText); setTimeout("ajax_verif_commande()", 20000); }
Page haut.php ou le bouton s'affiche
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 <?php header ("Cache-Control: no-cache"); include('../includes/identifiants.php'); $req_news_com = $bdd->prepare('SELECT new_com FROM commandes WHERE new_com = :nouv_com'); $req_news_com->bindValue('nouv_com', '0', PDO::PARAM_INT); try { $req_news_com->execute(); $total_req_news_com = $req_news_com->rowCount(); } catch (PDOException $e) { echo 'Error : ' . $e->getMessage(); die(); } if ($total_req_news_com > 0) { echo'<div class="tabs_rouge">'; echo'<a href="/admin/admin.php?page=aff_com" title="Il y a une nouvelle commande"><span>New Commande</span></a>'; echo'</div>'; } $req_news_com->closeCursor(); ?>
et enfin mon script js qui �met un son.
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3 <?php echo'<div id="div_nbr_commande"></div>'; ?>
sans oublier
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 <script type="text/javascript"> soundManager.setup( { url: '<?php echo ROOTPATH ; ?>/swf/', onready: function() { var mySound = soundManager.createSound( { id: 'aSound', url: '<?php echo ROOTPATH ; ?>/swf/ringtones.mp3' }); mySound.play(); },ontimeout: function() {} }); </script><br><br>Merci de votre aide.
Code : S�lectionner tout - Visualiser dans une fen�tre � part echo'<script type="text/javascript" src="'.ROOTPATH.'/js/soundmanager2.js"></script>';
Partager