3
Here lists all records that when clicking edit opens a modal with description value.
<?php foreach ($beneficios as $v): ?>
<tr>
<td><?= $v->id; ?></td>
<td class='descricao'><?= $v->descricao; ?></td>
<td class="actions actions-fade">
<a data-toggle="modal" id="<?= $v->id; ?>" class="beneficio" data-target="#<?= $v->id; ?>"><i class="fa fa-pencil"></i></a>
<a href="javascript:void(0);" id="<?= $v->id; ?>" class="delete-row deletar-beneficio"><i class="fa fa-trash-o"></i></a>
</td>
</tr>
How do I change the content of td that has the Description class? By putting in it the same content that ajax is receiving, see:
function alterarBeneficio(dados) {
$.ajax({
url: path + 'administrador/alterarBeneficio',
type: 'POST',
data: {'dados': dados},
success: function (response) {
if (parseInt(response) === 1) {
// Preciso colocar uma função aqui que altere o conteudo da TD, colocando o conteudo que foi passado na variavel dados, é possivel?
$(".alterado").show(500);
setTimeout(function () {
$(".alterado").fadeOut(1000);
}, 3000);
} else {
console.log('ocorreu um erro!');
}
},
error: function (erro, er) {
console.log(erro, er);
}
});
}
I put this code $('td .Description'). text('Testandooooo'); but does not change any content when successful :/
– viniciussvl
@Viniciusaquino sorry, I put the separate selector, actually it is together
td.descricao
instead oftd .descricao
- updated the response– andrepaulo
Now it’s gone, but it changes the content of all the tds, how can I make it change only the td the guy selected?
– viniciussvl
puts the whole code, where Voce fires that event? by a button? where that button is in html
– andrepaulo
I trigger the event in Submit that is inside a modal, I put all the code here: https://jsfiddle.net/etn8dpnz/
– viniciussvl
you have id on your modal right? or then on
response
pq in the same td as Voce has the classdescricao
, Vocetb has theid
in it, then Voce uses it as selector ex.$('#' + response.id).text('text');
– andrepaulo
I’m trying to return the id but it gives Undefined: console.log(Response.id);
– viniciussvl
Let’s go continue this discussion in chat.
– andrepaulo