Last active
August 29, 2015 14:11
-
-
Save devdays/b14817f0bb4b0831fd67 to your computer and use it in GitHub Desktop.
Object JavaScript -- Loading template and data from files using Mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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