Mercurial > repos > jankanis > blast2html
comparison NCBI Blast reference example_files/remote_data_provider.js @ 31:344cd76f6fd2
rename NCBI reference example
author | Jan Kanis <jan.code@jankanis.nl> |
---|---|
date | Thu, 15 May 2014 16:59:18 +0200 |
parents | Blast output page example_files/remote_data_provider.js@bad241dc701f |
children |
comparison
equal
deleted
inserted
replaced
30:2143f62809d0 | 31:344cd76f6fd2 |
---|---|
1 //========================================================================================================= | |
2 function RemoteDataProvider(sUrl) { | |
3 this.iActiveRequests = 0; | |
4 this.sUrl = sUrl; | |
5 } | |
6 | |
7 //------------------------------------------------------------------------------------------------------------- | |
8 RemoteDataProvider.prototype.GetHttpObj = function() { | |
9 var oHttpObj = null; | |
10 try { | |
11 oHttpObj = new ActiveXObject("Msxml2.XMLHTTP"); | |
12 } catch(e) { | |
13 try { | |
14 oHttpObj = new ActiveXObject("Microsoft.XMLHTTP") | |
15 } catch(oc) { | |
16 oHttpObj = null; | |
17 } | |
18 } | |
19 if (!oHttpObj && typeof XMLHttpRequest != "undefined") { | |
20 oHttpObj = new XMLHttpRequest(); | |
21 } | |
22 return oHttpObj; | |
23 } | |
24 | |
25 //------------------------------------------------------------------------------------------------------------- | |
26 RemoteDataProvider.prototype.Request = function(sRequest, method) { | |
27 var oHttpObj = this.GetHttpObj(); | |
28 if (null == oHttpObj) return; | |
29 | |
30 method = (!method) ? "GET" : "POST"; | |
31 var sURL = (method == "GET") ? this.sUrl + "?" + sRequest : this.sUrl; //alert(sURL); | |
32 this.iActiveRequests++; | |
33 var oThis = this; | |
34 oHttpObj.onreadystatechange = function () { | |
35 if (oHttpObj.readyState == 4 && oHttpObj.status == 200) { | |
36 oThis.onSuccess(oHttpObj); | |
37 oThis.iActiveRequests--; | |
38 oThis.onStop(); | |
39 } else if(oHttpObj.readyState == 4 && oHttpObj.status != 200) { | |
40 oThis.onError(oHttpObj); | |
41 oThis.iActiveRequests--; | |
42 oThis.onStop(); | |
43 } | |
44 }; | |
45 | |
46 if (oHttpObj.readyState != 0) oHttpObj.abort(); | |
47 this.onStart(); | |
48 oHttpObj.open(method, sURL, true); | |
49 // oHttpObj.setRequestHeader('Cache-Control', 'no-cache'); | |
50 var params = (method == "GET") ? null : sRequest; | |
51 if (params) { | |
52 oHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
53 oHttpObj.setRequestHeader("Content-length", params.length); | |
54 oHttpObj.setRequestHeader("Connection", "close"); | |
55 } | |
56 oHttpObj.send(params); | |
57 } | |
58 | |
59 //------------------------------------------------------------------------------------------------------------- | |
60 RemoteDataProvider.prototype.onSuccess = function(obj) { | |
61 alert(["success:", this.iActiveRequests, obj.responseText]); | |
62 } | |
63 | |
64 //------------------------------------------------------------------------------------------------------------- | |
65 RemoteDataProvider.prototype.onStart = function() { | |
66 // alert(["start:", this.iActiveRequests]); | |
67 } | |
68 | |
69 //------------------------------------------------------------------------------------------------------------- | |
70 RemoteDataProvider.prototype.onStop = function() { | |
71 // alert(["start:", this.iActiveRequests]); | |
72 } | |
73 | |
74 //------------------------------------------------------------------------------------------------------------- | |
75 RemoteDataProvider.prototype.onError = function(obj) { | |
76 //alert(["error:", this.iActiveRequests, obj.status]); | |
77 } | |
78 | |
79 |