1
Good morning friends, I have this code:
$(document).ready(function(){
$('button').on('click',function(e){
e.preventDefault();
var codigo = $(this).attr('id');
$.ajax({
type: 'post',
url: '<?= base_url('posts/apaga'); ?>',
data: 'codigo='+codigo,
success: function(msg){
if(msg.indexOf("Erro") > -1){
$('#ret_apaga_post').html(msg);
}else{
$('#reload_post').html(msg);
}
}
});
});
});
The situation is that I have a list of data returned from the database, and I have a delete button for each record.
What happens is that depending on the return PHP
, need to click on different Ivs. I found tips on msg.indexOf("Erro")
, about jquery contains selector
and also str.match(/Erro/)
, but only work the first time.
I also tried to add to ajax cache: false
, also unsuccessful.
Thanks in advance.
Ah! And I advise avoid short tags with PHP, use
<?php echo
instead of<?=
– Samuel Fontebasso
Friend, thanks for the help, I saw, your code works, but it was not necessary. I just realized that my code is correct. My mistake was that I was changing the
DOM
and without usingmutation observer
or re-water theJquery
on the page, it stops working even.– Luiz
Perfect, I didn’t really realize there were problems, just not following the pattern I recommend, but that’s not why it wouldn’t work :)
– Samuel Fontebasso
Do you have any alternative to
mutation observer
? I think the code too big and I didn’t even feel like using, at the moment I choose to always reload the javascript on the page, but seems to gambiarra right.– Luiz
AH! Thank you for sharing this about the
mutation observer
I have always had this kind of problem that is not very clear in the question (or I that does not work well in the morning kkk), but I understood. Tell me more about how you solved your problem!!– Samuel Fontebasso