Mercurial > hg > batmud > gmap2
annotate lib/util.js @ 305:585a8fb4a286 gmap2
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 11 Sep 2017 13:25:18 +0300 |
parents | 96ce03724648 |
children |
rev | line source |
---|---|
244 | 1 function XCreateXmlHTTPRequest() |
2 { | |
162 | 3 try { |
244 | 4 if (typeof ActiveXObject != 'undefined') |
162 | 5 return new ActiveXObject('Microsoft.XMLHTTP'); |
244 | 6 else |
7 if (window["XMLHttpRequest"]) | |
162 | 8 return new XMLHttpRequest(); |
244 | 9 } |
10 catch (e) { | |
162 | 11 changeStatus(e); |
12 } | |
13 return null; | |
244 | 14 } |
15 | |
162 | 16 |
267
96ce03724648
Add error handler callback.
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
17 function XDownloadUrl(url, callback, errcallback) |
244 | 18 { |
162 | 19 var status = -1; |
20 var request = XCreateXmlHTTPRequest(); | |
21 if (!request) | |
22 return false; | |
23 | |
244 | 24 request.onreadystatechange = function() |
25 { | |
26 if (request.readyState == 4) | |
27 { | |
162 | 28 try { |
29 status = request.status; | |
244 | 30 } |
31 catch (e) { | |
162 | 32 // Usually indicates request timed out in FF. |
33 } | |
244 | 34 if (status == 200) |
35 { | |
162 | 36 callback(request.responseText, request.status); |
37 request.onreadystatechange = function() {}; | |
38 } | |
267
96ce03724648
Add error handler callback.
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
39 else |
96ce03724648
Add error handler callback.
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
40 if (typeof(errcallback) == "function") |
305 | 41 errcallback(status); |
162 | 42 } |
43 } | |
244 | 44 |
162 | 45 request.open('GET', url, true); |
46 try { | |
47 request.send(null); | |
244 | 48 } |
49 catch (e) { | |
162 | 50 changeStatus(e); |
51 } | |
244 | 52 } |