diff Blast output page example trimmed_files/remote_data_provider.js @ 1:ffe82516a83c

add trimmed down html example
author Jan Kanis <jan.code@jankanis.nl>
date Tue, 06 May 2014 17:36:10 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Blast output page example trimmed_files/remote_data_provider.js	Tue May 06 17:36:10 2014 +0200
@@ -0,0 +1,79 @@
+//=========================================================================================================
+function RemoteDataProvider(sUrl) {
+    this.iActiveRequests = 0;
+    this.sUrl = sUrl;
+}
+
+//-------------------------------------------------------------------------------------------------------------
+RemoteDataProvider.prototype.GetHttpObj = function() {
+    var oHttpObj = null;
+    try {
+        oHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
+    } catch(e) {
+        try {
+            oHttpObj = new ActiveXObject("Microsoft.XMLHTTP")
+        } catch(oc) {
+            oHttpObj = null;
+        }
+    }
+    if (!oHttpObj && typeof XMLHttpRequest != "undefined") {
+        oHttpObj = new XMLHttpRequest();
+    }
+    return oHttpObj; 
+}
+
+//-------------------------------------------------------------------------------------------------------------
+RemoteDataProvider.prototype.Request = function(sRequest, method) {
+    var oHttpObj = this.GetHttpObj();
+    if (null == oHttpObj) return;
+
+    method = (!method) ? "GET" : "POST";
+    var sURL = (method == "GET") ? this.sUrl + "?" + sRequest : this.sUrl;        //alert(sURL);    
+    this.iActiveRequests++;
+    var oThis = this;
+    oHttpObj.onreadystatechange = function () {
+        if (oHttpObj.readyState == 4 && oHttpObj.status == 200) {
+            oThis.onSuccess(oHttpObj);
+            oThis.iActiveRequests--;    
+            oThis.onStop();    
+        } else if(oHttpObj.readyState == 4 && oHttpObj.status != 200) {
+            oThis.onError(oHttpObj);
+            oThis.iActiveRequests--;    
+            oThis.onStop();    
+        }
+    };
+    
+    if (oHttpObj.readyState != 0) oHttpObj.abort();
+    this.onStart();
+    oHttpObj.open(method, sURL, true);
+//    oHttpObj.setRequestHeader('Cache-Control', 'no-cache');
+    var params = (method == "GET") ? null : sRequest;
+    if (params) {
+        oHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+        oHttpObj.setRequestHeader("Content-length", params.length);
+        oHttpObj.setRequestHeader("Connection", "close");
+    }
+    oHttpObj.send(params);
+}
+
+//-------------------------------------------------------------------------------------------------------------
+RemoteDataProvider.prototype.onSuccess = function(obj) {
+    alert(["success:", this.iActiveRequests, obj.responseText]);
+}
+
+//-------------------------------------------------------------------------------------------------------------
+RemoteDataProvider.prototype.onStart = function() {
+//    alert(["start:", this.iActiveRequests]);
+}
+
+//-------------------------------------------------------------------------------------------------------------
+RemoteDataProvider.prototype.onStop = function() {
+//    alert(["start:", this.iActiveRequests]);
+}
+
+//-------------------------------------------------------------------------------------------------------------
+RemoteDataProvider.prototype.onError = function(obj) {
+    //alert(["error:", this.iActiveRequests, obj.status]);
+}
+
+