0
I have a table in a view, which lists the modules, with each module and each user, and a checkbox that indicates whether or not the user has access to the module, and I want in the action of changing the checkbox 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!');
}
});
});
});
That url Pessoa/Acesso
is a action of a controller that will update in BD, passing as parameters the user, cod_modulo and the access that if the checkbox is checked is 1, if not 0.
So every time I click the checkbox, it will send an update to the bank via POST for AJAX..
But now I was in doubt, do this will consume a lot network? Can it stay slow? Performance? I must update every time the user clicks on the checkbox?
I believe the most appropriate question would be "I must update each time the user clicks on the checkbox"? have other fields on this screen? could not use a refresh button?
– Ricardo Pontual
Dude, now I’m at work and the code is on my personal laptop... but it’s basically a table, with the code and module name, user name and checkbox if he has permission or not... I thought of doing something like he marks all checkboxes and then click on save and save all... however, I do not know how to pass this list of users to my controller... I know that with the code it would be easier to help me, as soon as I get it I put it here
– maiconfriedel
Then I thought of this alternative for ajax, but then I was in doubt about performance/network
– maiconfriedel