aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/fiveui/firefox/ajax.js
blob: da95c382dcb7da1b414da1e4b1902b2d7381220f (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
37

var fiveui  = fiveui || {};
var Request = require('request').Request;

(function() {

fiveui.ajax = fiveui.ajax || {};

/**
 * 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.
 */
fiveui.ajax.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();

};

})();