简体   繁体   中英

how to get result array with getJson CodeIgniter

my code :
model :

function get_all_transaksi_proses() {   
        $rs = $this->db->query("SELECT a.id_transaksi, ETC");
        return $rs;
    }

control :

public function ambilDataTransaksi() {
            $data=$this->transaksi->get_all_transaksi_proses();
             echo json_encode(array("result" => $data->result_array()));
        }

view :

$.getJSON("<?php base_url();?>transaksiDigorCont/ambilDataTransaksi", function(data) {
        alert("jhjh");

    });

this my code but it cant show alert("jhjh"), so it can't in to function(data) ?

See the $.getJSON documentation:

jQuery.getJSON( url [, data ] [, success( data, textStatus, jqXHR ) ] )

It expects a URL as the first argument.

You should be doing like:

$.getJSON( "<?php echo base_url(); ?>controllername/somefunction", function( data ) {
   //do something with data
});

and in your controller, create a function say, ' somefunction ', and

//controller code
function somefunction() {
 //load model if not already done in constructor
 //get data from model
  $data = $this->your_model->get_all_transaksi_proses();
  echo json_encode($data);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM