[英]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) ? 这是我的代码,但无法显示alert(“ jhjh”),因此无法进入function(data)吗?
See the $.getJSON documentation: 请参阅$ .getJSON文档:
jQuery.getJSON( url [, data ] [, success( data, textStatus, jqXHR ) ] )
It expects a URL as the first argument. 它期望将URL作为第一个参数。
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 然后在您的控制器中创建一个说“
somefunction
”的函数,然后
//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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.