I have a code that when clicking the button it opens a function in javascript
. In this function, a part of the code uses Ajax
. I need you to click on this button to change the color of the button, the text content and display a message next to a photo. So far I have been able to change only the color and text of the button, but the message only appears when reloading the page. I do not know what's going wrong. My entire code is in MVC .
Javascript code:
$(document).on('click', '.semEmi', function () {
var t = $(this);
var seletor_id_foto = '#input_' + $(this).attr('id');
var id_foto = $(seletor_id_foto).val();
$.SmartMessageBox({
title: "<?= $this->lang->line("con_inflaud_jus_msg_title "); ?>",
content: "<?= $this->lang->line("con_inflaud_jus_msg_d "); ?>",
buttons: "[<?= $this->lang->line("con_inflaud_jus_msg_btn_n "); ?>][<?= $this->lang->line("con_inflaud_jus_msg_btn_y "); ?>]",
input: "text",
inputValue: "",
placeholder: "<?= $this->lang->line("con_inflaud_jus_msg_place "); ?>"
}, function (ButtonPress, Value) {
if (ButtonPress == "<?= $this->lang->line("con_inflaud_jus_msg_btn_n "); ?>") {
return 0;
} else {
if (Value == "") {
notifica('<?=$this->lang->line("con_inflaud_msg_erro_title"); ?>', '<?= $this->lang->line("con_inflaud_jus_msg_inpmpt"); ?>', 4000);
} else {
$.ajax({
type: "POST",
url: "Controller/Funcao/" + id_foto + "/2",
data: {
justificativa: Value
},
dataType: "json",
success: function (r) {
if (r) {
$(t).parent().parent().next().find('.graf_lau').show();
$(t).parent().parent().next().find('.blockquote').show();
//$(t).parent().parent().next().find('blockquote > .graf_lau').css('display','block');
$(t).parent().parent().next().find('.img_lau_d').show();
$(t).parent().parent().next().find('.img_lau_a').css('display', 'none');
$(t).removeClass('semEmi btn-default');
$(t).addClass('comEmi btn-warning');
$(t).empty();
$(t).append('<span class="btn-label"><i class="fa fa-check-square-o"></i></span><?= $this->lang->line("con_inflaud_afe_comEmi"); ?>');
} else {
notifica('<?= $this->lang->line("con_inflaud_msg_erro_title"); ?>', '<?= $this->lang->line("con_inflaud_msg_erro_d"); ?>', 4000);
}
}
});
}
}
});
});
HTML:
<div class="col col-lg-2">
<div class="btn_semEmi" id="semEmi">
<input type="hidden" id="input_semEmi<?= $l->img_id?>" name="id_foto" value="<?= $l->img_id?>">
<a href="javascript:void(0);" id="semEmi<?= $l->img_id?>" id-foto="<?= $l->img_id?>" class="btn btn-labeled btn-default pull-right semEmi"> <span class="btn-label"><i class="fa fa-ban"></i></span><?= $this->lang->line("con_inflaud_afe_semEmi"); ?></a>
</div>
</div>