Permalink
Browse files

Changing requests over to ajax, now that it supports cross domain req…

…uest.
  • Loading branch information...
1 parent d47844c commit 065a5625991b66faa2bb024d738febe3f62a6b39 @kristopher committed Jul 6, 2013
Showing with 20 additions and 23 deletions.
  1. +20 −23 neocities-guestbook.js
View
@@ -1,32 +1,30 @@
var Guestbook = (function() {
- var self = this,
- callbacks = [],
- jsonp_callback = function(json) {
- self.entries = json;
- runCallbacks();
- }, _form;
+ var self = this, callbacks = [], _form;
self.entries = [];
self.subdomain = window.location.href.replace(/\.neocities\.org/i, '');
- function bind(callback) {
- callbacks.push(callback);
- }
-
- function getPage(page) {
- var script = document.createElement('script');
- script.type = "text/javascript";
- script.src = "http://neocities-guestbook.herokuapp.com?key=" + window.encodeURIComponent(self.subdomain) + "&page=" + page + "&callback=Guestbook.jsonp_callback";
- document.body.appendChild(script);
+ function getPage(page, callback) {
+ $.get("http://neocities-guestbook.herokuapp.com", { page: page }, function(json) {
+ self.entries = json
+ callback.call(self, page, json)
+ });
}
- function runCallbacks() {
- callbacks.forEach(function(callback) {
- try {
- callback.call(self, self.entries);
- } catch(e) {
- (console || {error: function() {}}).error(e);
- }
+ function CreateEntry(name, msg, callback) {
+ $.ajax({
+ url: "http://neocities-guestbook.herokuapp.com",
+ type: 'POST',
+ data: {
+ name: name,
+ message: msg
+ },
+ dataType: 'json',
+ success: function(json) {
+ self.entries.push(json);
+ callback.call(this, json);
+ },
+ error: callback
});
}
@@ -85,7 +83,6 @@ var Guestbook = (function() {
self.form = form;
self.bind = bind;
- self.jsonp_callback = jsonp_callback;
self.getPage = getPage;
return self;

0 comments on commit 065a562

Please sign in to comment.