2
I have a modal that opens at the end of an action (Example: Disable User). I am building the modal and wanted it to receive the text present in an ajax variable. Check code:
$.ajax({
url: "desativarUsuario.php",
type: 'post',
data: {
codigosDesativar: paraDesativar.map(function () {
return this.cod_user
}).get()
},
success: function (resposta) {
resposta = JSON.parse(resposta);
console.log(resposta, typeof resposta, typeof resposta[0], resposta[1]);
if (resposta[0]) {
var tabela = $('#tableUsuario tr');
$.each(tabela, function(index, tr) {
var checkbox = $(tr).find("input:checkbox");
if ($(checkbox).is(':checked')) {
$(tr).find(".status").text("Inativo");
$(tr).find(".status").css("color", "#BD362F");
$(tr).find(".inativo").addClass('hide');
$(tr).find(".ativo").removeClass('hide');
}
});
}
alert(resposta[1]);
}
});
The variable resposta
returns: Array [ true, "Usuário foi desativado com Sucesso!" ]
How to move inside the modal below this message "User has been Successfully Disabled!":
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p>AQUI QUERIA A MENSAGEM@!!!!!!</p>
<p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Just one other related question:
if($ativar==2){<script>$(".modal-body p").html("Selecione pelo menos um usuário que deseja desativar!");
 $(document).ready(function(){
 $("#modalMsgAviso").modal('show');
 });</script>}
reports missing error '<'. What may be?– Rodrigo Segatto
Yes, you can say I’m here?
– vmontanheiro
Why did you use that <script> tag inside if ? Your code should already be inside one, you don’t need to put another.
– vmontanheiro
I edited the @vcrzy
– Rodrigo Segatto
Oops. It worked.?
– vmontanheiro
My code is not inside a script tag. It’s inside a PHP. I should take it anyway?
– Rodrigo Segatto
Here’s what you do. Take the $(".modal-body p"). html("Select at least one user you want to deactivate!"); and put inside the ready Ocument as well. Then you echo everything. For example: if($activate==2){ echo '<script>your code here</script>'; If it doesn’t work out, I suggest opening another question or putting it online, so I can see it and help you solve it. I’m going to lunch and then we’re there, thanks
– vmontanheiro
It worked, man. Thank you :D
– Rodrigo Segatto
hahahaha for nothing. open
– vmontanheiro