Skip to content

Instantly share code, notes, and snippets.

@dmulvi
Last active August 29, 2015 14:02
Show Gist options
  • Save dmulvi/599bec2ab5d56739af52 to your computer and use it in GitHub Desktop.
Save dmulvi/599bec2ab5d56739af52 to your computer and use it in GitHub Desktop.
Simple jQuery ajax GET request
/*
* Task 2 - fetch some db results via ajax call and display in a table.
*/
var admixt_task2 = {
url: '/followers',
fetch: function(){
var self = this;
$.get(this.url)
.done(function(data) {
var json = JSON.parse(data);
self.fillTable(json);
})
.fail(function(data) {
console.log('oh noes!');
});
},
fillTable: function(data) {
var source = $("#table-template").html();
var template = Handlebars.compile(source);
var test = {followers: data};
var html = template(test);
$('#results').html(html);
$('#followers').dataTable();
$('#trigger-task2').hide();
}
}
$(document).ready(function(){
$('#trigger-task2').click(function(){
admixt_task2.fetch();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment