nsinject.js
authorAlan Knowles <alan@roojs.com>
Mon, 24 Sep 2012 05:00:58 +0000 (13:00 +0800)
committerAlan Knowles <alan@roojs.com>
Mon, 24 Sep 2012 05:00:58 +0000 (13:00 +0800)
nsinject.js

index 9ac0731..47dcebe 100644 (file)
@@ -279,6 +279,57 @@ NS = {
     },
     
     
+    downloadgetdata : function (url,data) {
+        
+       
+        var xmlhttp = new XMLHttpRequest();
+                    
+        xmlhttp.open("GET", url,true);
+        xmlhttp.responseType = 'arraybuffer';
+        //xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
+        //var kv = [];
+        //for(var i in data) {
+        //    kv.push(i +'=' + encodeURIComponent(  data[i]));
+        //}
+        
+
+        xmlhttp.onload=function() {
+           
+            var ar= [];
+             
+            var r = new Uint8Array(xmlhttp.response);
+            for (i=0;i<r.byteLength;i++) {
+                ar.push(r[i]);
+            }
+            
+            // location name for location download.
+            var pref = '';
+            if (document.getElementById('hddn_crit_32')) {
+                //stock.
+                pref =  document.getElementById('hddn_crit_32').value ;
+            } else {
+                // accounts.
+                pref = document.getElementsByClassName('pt_title')[0].innerText.replace(/\s+$/,'').replace(/\//g, '');
+            }
+            
+            console.log(
+                JSON.stringify ({
+                    requesturl : url,
+                    method: 'nsdownloadpage',
+                    filename : pref+ '-' + NS.id + '.csv',
+                    headers : xmlhttp.getAllResponseHeaders(),
+                    contentType:xmlhttp.getResponseHeader("Content-Type"),
+                    data: ar
+                }));
+           
+        }
+        
+        xmlhttp.send(kv.join('&'));
+           
+    },
+    
+    
+    
     downloaddata : function (url,data) {