So I found only 1 question that was similar to mine, and the answer didn’t really help none so I am hoping asking with my own code might help me find the answer I am looking for.
I am wanting to add sound to my shoutbox when a new post is made. I believe that the piece of code that the play sound function would go would be here
function shouts() {
clearTimeout(getshout);
var xmlHttp = (window.XMLHttpRequest) ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET", "shoutbox/shouts.php?i=" + Math.random());
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (parseInt(this.responseText) > current_shouts) {
getshouts();
current_shouts = parseInt(this.responseText);
}
getshout = setTimeout("shouts()", 1000);
}
}
xmlHttp.send(null);
}
But I am not 100% sure, I do know that this is where it checks for new entries in the database, the corresponding php code that is called by this function is
<?php
require_once("../config.php");
echo implode(mysql_fetch_assoc(mysql_query("SELECT COUNT(id) FROM shout")));
?>
I am pretty sure that this code doesn’t have to be touched in order to do this. I have done searches on Google, and checked multiple forums but I have yet to find a way that actually works, I am not asking for you guys to write the code for me, just give me a push in the right direction!
If there is anything else needed please let me know and I will edit my post.
Thanks, Casey
Somewhere on your page have
And on getting a new shout (maybe before the call to
getshouts()) do