How to block tr after clicking once

2

I have several table row and when I click on a <tr> it runs this script:

 $(function(){
            $('tr').click(function(){
            $("tr").prop("disabled", true);
            var id = $(this).attr('id');
            $.post("shopweb_item.php",{id: id}, function(data){
              $('#resultado').html(data);
              $("#comprar").prop("disabled", false);
            });
          });
        });

Only I even using:

$("tr").prop("disabled", true);

If the user clicks the request more than once and repeated then the return of the shopweb_item.php is a modal and ends up opening more than once is after I close still the page becomes dark and impossible to click, someone has Any ideas?

I took $("tr").prop("disabled", true); from this other script:

  // evento de "submit"
        $("#comprar").click(function (event) {
            // parar o envio para que possamos faze-lo manualmente.
            event.preventDefault();
            // capture o formulário
            var form = $('#formulario')[0];
            // crie um FormData {Object}
            var data = new FormData(form);
            // caso queira adicionar um campo extra ao FormData
            // data.append("customfield", "Este é um campo extra para teste");
            // desabilitar o botão de "submit" para evitar multiplos envios até receber uma resposta
            $("#comprar").prop("disabled", true);
            // processar
            $.ajax({
                type: "POST",
                enctype: 'multipart/form-data',
                url: "enviar.php",
                data: data,
                processData: false, // impedir que o jQuery tranforma a "data" em querystring
                contentType: false, // desabilitar o cabeçalho "Content-Type"
                cache: false, // desabilitar o "cache"
                timeout: 600000, // definir um tempo limite (opcional)
                // manipular o sucesso da requisição
                success: function (data) {
                    console.log(data);
                    $("#msg").html(data);
                    // reativar o botão de "submit"
                    //limpar form
                      $('#formulario').each (function(){
                          this.reset();
                        });
                    $("#comprar").prop("disabled", false);
                },
                // manipular erros da requisição
                error: function (e) {
                    console.log(e);
                    // reativar o botão de "submit"
                    $("#comprar").prop("disabled", false);
                }
            });
        });

But I get the data of a <from> I do not know how to get the id of <tr> with this second script.

HTML:

<tr id="<?php echo $shopweb->id_shop; ?> ">
 <td><img src="<?php echo "$shopweb->icone"; ?>"></td>
 <td><?php echo "$shopweb->nome"; ?></td>
 <td><?php echo "$shopweb->categoria_s"; ?></td>
 <td><?php echo "$shopweb->tipo_s"; ?></td>
 <td><?php echo "$shopweb->level"; ?></td>
 <td><?php echo "$shopweb->preco"; ?></td>
</tr>
    
asked by anonymous 05.01.2018 / 17:22

1 answer

4

The property disabled has no effect on tr.

What you can do is disable the click event when you click on tr .

For example:

$("tr").click(function(event) {
    alert("Clicado!");
    $(this).off("click");
});

See working here .

    
05.01.2018 / 17:44