aboutsummaryrefslogtreecommitdiff
path: root/src/js/firefox/lib/ajax.js
blob: 404deeeabd8e00081b7d117e2bc0dba5fa2676c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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();

};

})();