jquery - PHP, Ajax, JSON, and Handlebars -


if redundant question please let me know , point me there, not finding exact question/answer combination nor mixture of two.

i have ajax in jquery calls function php page. without handlebars json data comes nice , pretty. no issues there. can't seem ajax write out results handlebars template. here code have now:

$.ajax({ type: "post",     url: "../includes/db_functions.inc.php",     data: ({ p : p, p2 : p2, f : f }),     datatype: "json",     success: function(results){ $.each(results, function(i, item){      var context = [       {             id : item[i].id,              clock_number : item[i].clock_number,      }     ],     template = handlebars.compile( $('#template').html() );     $('table.entries').append( template(context) ); }); } }); 

anyone know might missing here? 99% sure in context area, not finding it.

[edit]

<table class="entries">     <script id="template" type="text/x-handlebars-template">             <tr>                 <td>{{id}}</td>                 <td>{{clock_number}}</td>             </tr>     </script> </table> 

from handlebars - getting started, say, leave out array , use object context

var context = {     id : item[i].id,      clock_number : item[i].clock_number, }, template = handlebars.compile($('#template').html()); $('table.entries').append(template(context)); 

in ajax success code, there's call $.each(results, function(i, item) {...}). in context, item ith element, if results array. maybe can reduce

success: function(results) {     var template = handlebars.compile($('#template').html());     $.each(results, function(i, context) {         $('table.entries').append(template(context));     }); } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -