This is my JSON and I want to know how can I show my information into page using handlebars template engine:
This is my template (script):
<script id="template-app" type="text/x-handlebars-template">
{{#each data}}
Email: {{email}} <br/>
First Name: {{first_name}} <br/>
Last Name: {{last_name}} <br/>
{{/each}}
</script>
And I send an ajax request to get the following JSON:
$(function(){
var theTemplateScript= $("#template-app").html();
var theTemplate= Handlebars.compile(theTemplateScript);
$.ajax({
url: 'http://localhost/cb/MOCK_DATA.json',
type: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function(data) {
var theCompiledHTML= theTemplate(data);
$(document.body).append(theCompiledHTML);
}
});
});
This is the JSON that above Ajax request get:
[{"first_name":"Betty","last_name":"Sims","email":"bsims0@studiopress.com"},
{"first_name":"Roger","last_name":"Mendoza","email":"rmendoza1@google.pl"},
{"first_name":"Albert","last_name":"West","email":"awest2@cornell.edu"},
{"first_name":"Bobby","last_name":"Lane","email":"blane3@ameblo.jp"},
{"first_name":"Julie","last_name":"Wheeler","email":"jwheeler4@google.ru"}]
It is not working, and I believe it is from template that I wrote!