diff options
Diffstat (limited to 'src/js/firefox/lib/ajax.js')
-rw-r--r-- | src/js/firefox/lib/ajax.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/js/firefox/lib/ajax.js b/src/js/firefox/lib/ajax.js new file mode 100644 index 0000000..404deee --- /dev/null +++ b/src/js/firefox/lib/ajax.js @@ -0,0 +1,36 @@ + +var fiveui = fiveui || {}; +var Request = require('request').Request; +var _ = require('underscore'); + +(function() { + +/** + * Use the request api to make an XHR request from the extension context. + * Behaves somewhat like the jQuery.ajax method, but only ever returns the text + * content of the response. + */ +exports.get = function(url, opts) { + + _.defaults(opts, { + success: function() {}, + error: function() {}, + }); + + Request({ + + url: url, + + onComplete:function(resp) { + if(resp.status == 200) { + opts.success(resp.text); + } else { + opts.error(); + } + }, + + }).get(); + +}; + +})(); |