Skip to content

Instantly share code, notes, and snippets.

@alloyking
Created December 1, 2012 02:23
Show Gist options
  • Save alloyking/4180245 to your computer and use it in GitHub Desktop.
Save alloyking/4180245 to your computer and use it in GitHub Desktop.
Sammy remote json load
//parse json plugin
(function($) {
Sammy.JSON.LoadJSON = function(app) {
app.helpers({
loadJSON: function(location, options, callback) {
options = $.extend(options, {json: true});
return new Sammy.RenderContext(this).load(location, options, callback);
}
});
}
})(jQuery);
//app.js
Sammy('#main', function() {
this.use(Sammy.JSON.LoadJSON);
var app = $.sammy('#mytag', function() {
this.get('#/contact', function(context) {
this.loadJSON('http://samedomain/api/getdata')
.then(function(items) {
$.each(items, function(i, item) {
context.log(item);
});
});
});
});
}).run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment