1 |
dpavlin |
46 |
/** |
2 |
|
|
* Class to perform simple synchronous AJAX Requests used for component loading. |
3 |
|
|
* @name Joose.SimpleRequest |
4 |
|
|
* @class |
5 |
|
|
*/ |
6 |
|
|
Class("Joose.SimpleRequest", { |
7 |
|
|
|
8 |
|
|
has: {_req: {}}, |
9 |
|
|
methods: { |
10 |
|
|
initialize: function () { |
11 |
|
|
if (window.XMLHttpRequest) { |
12 |
|
|
this._req = new XMLHttpRequest(); |
13 |
|
|
} else { |
14 |
|
|
this._req = new ActiveXObject("Microsoft.XMLHTTP"); |
15 |
|
|
} |
16 |
|
|
}, |
17 |
|
|
/** |
18 |
|
|
* Fetches text from an URL |
19 |
|
|
* @name getText |
20 |
|
|
* @param {string} url The URL |
21 |
|
|
* @function |
22 |
|
|
* @memberof Joose.SimpleRequest |
23 |
|
|
*/ |
24 |
|
|
getText: function (url) { |
25 |
|
|
this._req.open("GET", url, false); |
26 |
|
|
try { |
27 |
|
|
this._req.send(null); |
28 |
|
|
if (this._req.status == 200 || this._req.status == 0) |
29 |
|
|
return this._req.responseText; |
30 |
|
|
} catch (e) { |
31 |
|
|
throw("File not found: " + url); |
32 |
|
|
return null; |
33 |
|
|
}; |
34 |
|
|
|
35 |
|
|
throw("File not found: " + url); |
36 |
|
|
return null; |
37 |
|
|
} |
38 |
|
|
} |
39 |
|
|
}) |