From within my scrip.js file, I'm using jquery $.post function to post some data (Actually as of right now I'm just trying get my call back to work so I can read some data).
$('document').ready(function(){
$.post("index.php/main/showData",
function(data){
console.log(data);
for (var name in data){
alert(name);
}
}, "json");
});
I'm using codeigniter to access to data the data from mysql:
class Main extends CI_Controller
{
function showData()
{
$this->load->model('ajax');
$array = array($this->ajax->getRecArray());
// $this->index();
echo json_encode($array);
}
My model
class Ajax extends CI_Model
{
function getRecArray()
{
$query = $this->db->query("SELECT * FROM record_table WHERE id = 1");
$row = $query->result();
return $row;
}
}
When I console.log(data) I get:
[[Object { id="1", name="scott"}]]
My question is, How do I access the individual properties or objects from with script.js? For example, how do I access the value of name in that Object array?