I'm stuck doin my job.. So I want 'flag' variables to hold some value for checking Ajax result after executed php file. The purpose of this is if the current value is not same with the 'flag' variables, then play the sound. It's a Queue System that I built with php, mysql and JQuery... So check this code
First check my jQuery
<script>
$(document).ready(function(){
setInterval(function(){loadDataPemandu()}, 2000);
});
function loadDataPemandu(door,session){
$( "h2" ).each(function(){
var tampungNilai = $(this).attr("id");
var link = "http://localhost/antrian_v2/js/ajax_act/AutoLoadPemandu.php";
$.ajax({
type : "POST",
dataType : "json",
url : link,
cache : false,
data : "TicketGroupId="+tampungNilai,
success : function(data) {
if(data.nomortiket == ""){
$( "h2#"+tampungNilai ).text("");
$( "td."+tampungNilai ).css({
"color": "black",
"background-color": "#4569de",
"font-style": "normal",
"font-weight": "bold",
});
$( "td."+tampungNilai ).removeAttr("jAlert");
} else {
$( "h2#"+tampungNilai ).text(data.nomortiket);
$( "h2#"+tampungNilai ).css({
"font-size" : "260%"
});
$( "td."+tampungNilai ).css({
"color": "black",
"background-color": "yellow",
"font-style": "normal",
"font-weight": "bold",
});
$( "td."+tampungNilai ).attr("jAlert", data.nomortiket);
}
});
}
}
</script>
and then I dynamically fill the table with Ajax Result above that always running 2 secs with setInterval
<table align="center" id="tableGue">
<tbody align="center" id="AutoLoadPemandu">
<!-- <tbody id="AutoLoadPemandu" align="center"> -->
<?php
include"/config/koneksi.php";
$DoorId = isset($_GET['door']) ? $_GET['door'] : '0';
$no = 1;
$qrySelect = "SELECT * FROM qm_ms_ticketgroup WHERE TicketGroupActive = 'Y' ORDER BY TicketGroupId";
$sqlSelect = mysql_query($qrySelect);
while($tg = mysql_fetch_array($sqlSelect)){
$TicketGroupId = $tg['TicketGroupId'];
$Datahead1 = "<tr>
<td align='center' valign='middle'>
<div class='nama_table'>
$tg[TicketGroupName]
</div>
</td>
</tr>";
$DataBody2 = "<tr>
<td align='center' valign='middle' class='$TicketGroupId nama_antrian'>
<h2 class='testtt' id='$TicketGroupId'></h2>
</td>
</tr>";
echo $Datahead1 . $DataBody2;
$no++;
}
?>
</tbody>
</table>
I want, if $('#TicketGroupId') filled by Ajax, then they will show sound once if the result same, but if the result has a new value then play the sound everytime that function running by setInterval.
Check this pics enter image description here
When setInterval running and found the new result in the queue, play the sound but if the result still the same after running setInterval, don't play the sound.
I need advice, hope you understand what i am trying to say... thank you guys...