Last active
August 29, 2015 14:02
-
-
Save dmulvi/599bec2ab5d56739af52 to your computer and use it in GitHub Desktop.
Simple jQuery ajax GET request
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
/* | |
* 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