|
1 | | -_$_APP_CLASS_$_._p_.recvCallback = function(request, userData) { |
2 | | - if (request.readyState == 4) { |
3 | | - if (request.status) { |
4 | | - _$_APP_CLASS_$_._p_.handleResponse |
5 | | - (request.status == 200 ? request.responseText : "", userData); |
6 | | - } |
7 | | - request.onreadystatechange = new Function; |
8 | | - } |
9 | | -}; |
10 | | - |
11 | | -_$_APP_CLASS_$_._p_.commResponseReceived = function(updateId) { |
12 | | -} |
13 | | - |
14 | | -_$_APP_CLASS_$_._p_.sendUpdate = function(url, data, userData, id) { |
15 | | - var xmlHttpReq = false; |
16 | | - if (window.XMLHttpRequest) { |
17 | | - xmlHttpReq = new XMLHttpRequest(); |
18 | | - } else if (window.ActiveXObject) { |
19 | | - try { |
20 | | - xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); |
21 | | - } catch (err) { |
22 | | - try { |
23 | | - xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); |
24 | | - } catch (err2) { |
| 1 | +_$_APP_CLASS_$_._p_.comm = new (function(handleResponse) { |
| 2 | + var handler = handleResponse; |
| 3 | + |
| 4 | + function Request(url, data, userData, id, timeout) { |
| 5 | + var request = false; |
| 6 | + var timer = null; |
| 7 | + var handled = false; |
| 8 | + |
| 9 | + function recvCallback() { |
| 10 | + if (request.readyState == 4) { |
| 11 | + if (handled) |
| 12 | + return; |
| 13 | + |
| 14 | + // console.log("recvCallback " + request.status); |
| 15 | + clearTimeout(timer); |
| 16 | + |
| 17 | + if (request.status == 200) |
| 18 | + handler(0, request.responseText, userData); |
| 19 | + else |
| 20 | + handler(1, null, userData); |
| 21 | + |
| 22 | + request.onreadystatechange = new Function; |
| 23 | + |
| 24 | + handled = true; |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + function handleTimeout() { |
| 29 | + request.onreadystatechange = new Function; |
| 30 | + handled = true; |
| 31 | + handler(2, null, userData); |
| 32 | + }; |
| 33 | + |
| 34 | + this.abort = function() { |
| 35 | + request.onreadystatechange = new Function; |
| 36 | + handled = true; |
| 37 | + request.abort(); |
25 | 38 | } |
| 39 | + |
| 40 | + if (window.XMLHttpRequest) |
| 41 | + request = new XMLHttpRequest(); |
| 42 | + else if (window.ActiveXObject) |
| 43 | + try { |
| 44 | + request = new ActiveXObject("Msxml2.XMLHTTP"); |
| 45 | + } catch (err) { |
| 46 | + try { |
| 47 | + request = new ActiveXObject("Microsoft.XMLHTTP"); |
| 48 | + } catch (err2) { |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + if (!request) |
| 53 | + return; |
| 54 | + |
| 55 | + request.open('POST', url, true); |
| 56 | + request.setRequestHeader("Content-type", |
| 57 | + "application/x-www-form-urlencoded;"); |
| 58 | + if (_$_CLOSE_CONNECTION_$_) |
| 59 | + request.setRequestHeader("Connection","close"); |
| 60 | + |
| 61 | + if (timeout > 0) |
| 62 | + timer = setTimeout(handleTimeout, timeout); |
| 63 | + request.onreadystatechange = recvCallback; |
| 64 | + request.send(data); |
26 | 65 | } |
27 | | - } |
28 | | - |
29 | | - xmlHttpReq.open('POST', url, true); |
30 | | - xmlHttpReq.setRequestHeader("Content-type", |
31 | | - "application/x-www-form-urlencoded;"); |
32 | | - if (_$_CLOSE_CONNECTION_$_) |
33 | | - xmlHttpReq.setRequestHeader("Connection","close"); |
34 | | - xmlHttpReq.onreadystatechange |
35 | | - = function() { _$_APP_CLASS_$_._p_.recvCallback(xmlHttpReq, userData); }; |
36 | | - xmlHttpReq.send(data); |
37 | | - |
38 | | - return xmlHttpReq; |
39 | | -}; |
| 66 | + |
| 67 | + this.responseReceived = function(updateId) { }; |
| 68 | + |
| 69 | + this.sendUpdate = function(url, data, userData, id, timeout) { |
| 70 | + return new Request(url, data, userData, id, timeout); |
| 71 | + }; |
| 72 | + })(_$_APP_CLASS_$_._p_.handleResponse); |
0 commit comments