Doubt - Send Ajax in Checkbox Click (Perfomance, Network)

0

I have a table in a view, which lists the modules, with each module and each user, and a checkbox that indicates whether the user has access to the module, and I want in the action of changing the checkbox to do the following ajax:

$(document).ready(function () {
  $('#activelist').change(function () {
    var valor = 0;
    if ($("#activelist").is(":checked")){
    valor = 1;
    } 
    var usuario = $(this).data("usuario");
    var cod_modulo = $(this).data("cod_modulo");
    var url = "Pessoa/Acesso";
    $.ajax({
                type: 'POST',
                url: url,
                data: { 'usuario': usuario, 'cod_modulo' : cod_modulo, 'acesso' : valor },
                dataType: 'html',
                success: function () {
                    alert("Sucesso!")
                },
                error: function () {
                    alert('Error loading Ajax!');
                }
            });
       });
  });

This url Pessoa/Acesso is a action of a controller that will update the BD, passing as parameters user , < in> cod_module and access that if the checkbox is checked it is 1 if not 0.

So every time I click on the checkbox, it will send an update to the bank via POST by AJAX .

But now I'm in doubt, is this going to consume a lot of network? Can you slow down? Performance? Should I update every time the user clicks the checkbox?

    
asked by anonymous 13.09.2018 / 14:39

0 answers