Home | Projects | Tutorials | Articles | live chat | Submit Project | Big Vote
 
Ajax Projects
.NET Frameworks
Java Frameworks
PHP Frameworks
Ruby Frameworks
Other Frameworks
Cool AJAX sites
Ajax Resources
Ajax Tools
JavaScript frameworks

 Home /  Tutorials / A quick introduction of using jTemplate against AJAX JSON data

A quick introduction of using jTemplate against AJAX JSON data





jQuery has a few template plugins, the most widely accepted is jTemplate. jTemplate is a JQuery template engine that works with AJAX and JSON data.

Read The Full Tutorial.
































jQuery has a few template plugins, the most widely accepted is jTemplate. jTemplate is a JQuery template engine that works with AJAX and JSON data. We can use jTemplate in the following steps:

First, download the JQuery JavaScript file and reference it in your web page:

   1. <scrip src="scripts/jQuery-jtemplates.min.js" type="text/javascript"></script>

<scrip src="scripts/jQuery-jtemplates.min.js" type="text/javascript"></script>

Second, define your template:

       1. <script type="text/html" id="TemplateResultsTable"> 
       2. {#template MAIN} 
       3. <table  cellpadding="10" cellspacing="0"> 
       4.   <tr> 
       5.     <th>Artist</th> 
       6.     <th>Company</th> 
       7.     <th>Title</th> 
       8.     <th>Price</th> 
       9.   </tr> 
      10.   {#foreach $T.d as CD} 
      11.     {#include ROW root=$T.CD} 
      12.   {#/for} 
      13. </table> 
      14. {#/template MAIN} 
      15. {#template ROW} 
      16. <tr class="{#cycle values=['','evenRow']}"> 
      17.   <td>{$T.Artist}</td> 
      18.   <td>{$T.Company}</td> 
      19.   <td>{$T.Title}</td> 
      20.   <td>{$T.Price}</td> 
      21. </tr> 
      22. {#/template ROW} 
      23. </script>

    Please note that we define the template in a script block, which can be accessed by its id; also, $T is a reference to the data item passed to the template.

    Third, call your web service in your script, designate the template and instantiate it with data.

       1. $(document).ready(function() { 
       2.           $.ajax({ 
       3.               type: "POST", 
       4.               url: "CDCatalog.asmx/GetCDCatalog", 
       5.               data: "{}", 
       6.               contentType: "application/json; charset=utf-8", 
       7.               dataType: "json", 
       8.               success: function(msg) { 
       9. //instantiate a template with data
      10.                   ApplyTemplate(msg);  
      11.               } 
      12.           }); 
      13.       }); 
      14. function ApplyTemplate(msg) { 
      15.       $(’#Container’).setTemplate($("#TemplateResultsTable").html()); 
      16.       $(’#Container’).processTemplate(msg); 
      17. }

For more info please visit Xun Ding’s excellent article Using jQuery with ASP .NET

source: vincenthomedev.wordpress

AddThis Social Bookmark Button
Top Projects
MessengerFX
MSN Web Messenger
ebuddy
e-messenger
ILoveIM
You Tube
AJAX file upload
KoolIM.com
Meebo
Ajax.NET Professional
Tutorials
JQuery Ajax File Upload and ASP.NET
WCF Service using ASP.NET AJAX Library
AJAX with jQuery and EasyWeb4J
Creating an Ajax Application with Script.aculo.us
AJAX in Java with DWR
Building Twitter Search using the ASP.NET Ajax Library Beta – Part II
Ajax Banner
Cancelling an Asynchronous PostBack in ASP.NET Ajax
JavaScript Basics
Developing a Wiki Seek Widget using AJAX