I am fetching the JSON using the library philsturgeon/codeigniter-restserver
When I check in the response section of console, I get the proper JSON values returned like
this: [{name:test,address:test},{name:test2,address:test2}].
On fronted I want these values to be displayed in the template. But it just returns {"readyState":1} when I do <%= JSON.stringify(ledgers) %>.
I call the template from my view like this:
$("#container-left").html(this.template({ledgers:app.ledgers.fetch()}));
My REST controller function looks like:
public function index_get()
{
$this->response($this->db->get('ledgers')->result());
}
Your aren’t using the
fetchmethod correctly. Becausefetchdoesn’t return the data when it is called so you need to provide thesuccesscallback to fill your template:The
_.eachfunction itself won’t return anything so you when you output the return value you get undefinied.You need to output the data inside your function with
<%= name %>Demo JSFiddle.