Request.js
[gitlive] / Request.js
1
2
3
4 Request = function(opts) {
5
6       
7     _this = this;
8     // do the request to get the task..
9     var r = new XMLHttpRequest({
10         
11         onreadystatechange : function()
12         {
13             print("Got result.");
14             if (this.status != 4) {
15                 return;
16             }
17             
18               
19             var res = JSON.parse(this.responseText);
20             
21             //print(JSON.stringify(res,null,4))
22             //print([ res.success , res.data.length ]);
23             if (!res.success || !res.data.length)  {
24                 print("NO tasks returned");
25                 callback([]);
26                 return;
27             }
28             
29             //print("Current task:" + JSON.stringify(_this.curTask,null,4));
30             if (opts.success) { 
31                 opts.success.call(opts.scope || this, res.data);
32             }
33         }
34         
35     });
36     
37     
38     var netrc  = Netrc.forHost('git.roojs.com');
39     
40       
41     
42     r.open('GET',
43            'http://roojs.com/admin.php' + opts.url + '?' + r.urlEncode(opts.params)
44            ,true, netrc.login, netrc.password  );
45     print("Getting current task: "  +
46             'http://roojs.com/admin.php' + opts.url + '?' + r.urlEncode(opts.params)
47          );        
48     r.send();
49         
50 }
51
52     
53     
54