bring bank data with Javascript

0

I have a <a href="javascript:void(0);" class="justificar" data-value="<?= $l->img_id?>"> that when clicking, I need to bring a data from the database, but I do not know how to pull this data to the screen. My code is in codeigniter, and when you click on <a href> it calls this class :

$(document).on('click','.justificar', function(){
var t = $(this);
$.SmartMessageBox({
title : "<?= $this->lang->line("con_inflaud_jus_msg_title"); ?>",
content : "<?= $this->lang->line("view_relat_iten_title_jus"); ?>",
buttons : "[<?= $this->lang->line("con_inflaud_jus_msg_btn_ok"); ?>]",

}, function(ButtonPress, Value) {
if(ButtonPress == "<?= $this->lang->line("con_inflaud_jus_msg_btn_ok"); ?>"){
return 0;
}
});
});

How do I get the data from the database

    
asked by anonymous 21.08.2015 / 14:17

2 answers

1

What you're trying to do is make an ajax call. You need to send a request to the server and treat it in the codeigniter to bring your data and then you retrieve the ajax return and display the content.

$( document ).ready(function () {
  // define o clique do botão
  $("#button").click(function () {
    // faz uma requisição ajax do tipo $_GET
    $.get("/teste/tempo", function (tempo) {
      // atualiza o campo input#tempo com o tempo
      $("#tempo").val(tempo);
    });
  });
});

On the controller side you create an action tempo and define the return

public function tempo()
{
    echo time();
} 

And so goes the humanity ...

---- Edit ----

Tip: It would be interesting if you separate the php from javascript because of separation of responsibility, let each control its own space.

    
21.08.2015 / 14:32
0

I've already done it another way. I created a class for the button and in the Javascript file I put the following code:

$(document).on('click', '.just', function (e) {
    logged();
    e.preventDefault();
    $.getJSON("Controller/funcao/" + $(this).attr("data-value"), function (j) {
        $('#jus_just').html(j);
        $('#myModal').modal('show');
    });
});

In this Controller I called the table and the field that stores the required field.

    
25.08.2015 / 15:01