Welcome Guest, Not a member yet? Register   Sign In
How to get value from controller with jquery
#6

I always do things like get result from query as array such as result_array() for multi dimension or single array like row_array() then simply
For example , in your case, I would do this
$res= $this->barang_model->get_autocomplete($id); //assume you get row_array as return
then
echo json_encode($res);
OR I usually wrap it up with success and message, data like this:
echo json_encode(array('success'=>1, 'message'=>'anything you want to read', 'data'=>$res));

My frontend at ajax,  I often using

Code:
$.post(yoururl,{optionaldata},function(result){
//you can check result data here
},'json')    //make sure you have 'json' to indicate that you need json as content type !
.done(function(result){
//I often do this here
if(result.success===1){
   console.log(JSON.stringify(result.data));//show all your json string as data
   console.log(JSON.stringify(result.data.stock)); //will show your stock value !
}
})
.fail(function(result){
//action for failures so on
});
Reply


Messages In This Thread
RE: How to get value from controller with jquery - by ciadvantage - 06-30-2017, 10:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB