Skip to content

Instantly share code, notes, and snippets.

@devdays
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/b14817f0bb4b0831fd67 to your computer and use it in GitHub Desktop.
Save devdays/b14817f0bb4b0831fd67 to your computer and use it in GitHub Desktop.
Object JavaScript -- Loading template and data from files using Mustache
<!DOCTYPE html>
<html>
<head>
<title>jQuery loads External Mustache Template</title>
</head>
<body>
<h3>Default Header</h3>
<div id="products"></div>
<script src="Scripts/jquery-2.0.2.js"></script>
<script src="Scripts/mustache.js"></script>
<script>
$(document).ready(function () {
$.getJSON(
'data/products2.txt', {},
function (productsData, textStatus, jqXHr) {
$.get('templates/productsList.mustache.html',
function (template, textStatus, jqXhr) {
var productHtml = Mustache.render(template, productsData);
$('#products').append(productHtml);
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment