comparison Blast output page example_files/remote_data_provider.js @ 0:bad241dc701f

add example input blast xml and output html page
author Jan Kanis <jan.code@jankanis.nl>
date Tue, 06 May 2014 17:05:58 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bad241dc701f
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