Function with ajax does not fully load

Asked

Viewed 94 times

1

I have a code that by clicking the button it opens a function in javascript. In this function, a part of the code uses Ajax. I need that, after clicking this button, that code changes the color of the button, the content of the text and presents a message next to a photo. So far I was able to change only the color and text of the button, but the message only appears when reloading the page. I don’t know what is going wrong. My entire code is on 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>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.