dongyouzhi7218 2018-12-04 10:11
浏览 60

使用AJAX和setInterval()保存值的标志变量

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...

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?