doubaran2438 2018-01-01 22:20
浏览 59
已采纳

当MySQL中的新记录 - HTML表格时发出哔声

So, I have a PHP - Symfony 3 project connected to a MySQL Database through an API to let customers place orders through an Android APP. I need the Browser to play a beep sound when a new order has been placed (orders are shown in an HTML table) So I guess the sound has to be played using Javascript when the table changes. Any ideas on how to accomplish this? Thank you in advance. I will post the index view code below if it helps

{% extends 'base.html.twig' %}

{% block body %}
<h1 class="page-header">Listado de Aderezos</h1>

<table class="table table-striped table-responsive" id="data">
    <thead>
        <tr>
            <th>Id</th>
            <th>Nombre</th>
            <th>Descripcion</th>
            <th style="display:none;">Deleteat</th>
            <th>Acciones</th>
        </tr>
    </thead>
    <tbody>
    {% set cont = 0 %}
    {% for Aderezo in aderezos %}
        <tr>
            <td><a href="{{ path('aderezo_show', { 'id': Aderezo.id }) }}">{{ Aderezo.id }}</a></td>
            <td>{{ Aderezo.nombre }}</td>
            <td>{{ Aderezo.descripcion }}</td>
            <td>{{ Aderezo.deleteAt }}</td>
            <td>
                <div class="btn-group">

                            <a id="viewedit{{ cont }}" class="btn btn-sm btn-outline-primary" href="{{ path('aderezo_show', { 'id': Aderezo.id }) }}">show</a>
                            {% set cont = cont + 1 %}

                            <a id="viewedit{{ cont }}" class="btn btn-sm btn-outline-primary" href="{{ path('aderezo_edit', { 'id': Aderezo.id }) }}">edit</a>
                            {% set cont = cont + 1 %}
                                <a class="btn btn-sm btn-outline-danger" href="{{ path('aderezo_delete', { 'id': Aderezo.id }) }}">Eliminar</a>                    </div>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>

<a class="btn btn-block btn-lg" href="{{ path('aderezo_new') }}">Crear Nuevo Aderezo</a>

<script>
    $( document ).ready(function() {
        $('#data').DataTable({

            destroy:true,
            language:{
                "sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_ registros",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningún dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "Buscar:",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Último",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                },
                "oAria": {
                    "sSortAscending":  ": Activar para ordenar la columna de manera ascendente",
                    "sSortDescending": ": Activar para ordenar la columna de manera descendente"
                }
            }

        });
    });

</script>
<script>
    $( document ).ready(function() {
        var contador = {{ cont }};
        while (contador >= 0){


            if ( $('#viewedit'+contador).text() =='show'){
                $('#viewedit'+contador).text("Ver");
            }

            if ($('#viewedit'+contador).text()=='edit'){
                $('#viewedit'+contador).text("Editar");
            }
            contador = contador - 1;
        }


    });
</script>
{% endblock %}
  • 写回答

1条回答 默认 最新

  • duangu4943 2018-01-02 16:05
    关注

    If it's a simple sound you can base64 encode the binary data of the file into a string. See this answer.

    Then play the sound through Javascript. See this answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了