NxTIC/js/lib/api-min.js

4 lines
893 B
JavaScript
Raw Normal View History

function APIClass(b){this.target=b}
APIClass.prototype={xhr:[],send:function(b,d,g){b.hasOwnProperty("path")||d({ModuleError:4});for(var a=0;a<this.xhr.length;a++)4==this.xhr[a].readyState&&(this.xhr=this.xhr.slice(0,a-1).concat(this.xhr.slice(a,this.xhr.length-1)));this.xhr.push(null);a=this.xhr.length-1;this.xhr[a]=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHttpRequest");console.log(b);var f=this;this.xhr[a].onreadystatechange=function(){if(4==f.xhr[a].readyState)if(-1<[0,200].indexOf(f.xhr[a].status))try{d(JSON.parse(f.xhr[a].responseText))}catch(b){d({ModuleError:1})}else d({ModuleError:3})};
var e=new FormData,c;for(c in b)"path"==c?e.append(c,b[c]):b[c]instanceof File?e.append(c,b[c]):e.append(c,JSON.stringify(b[c]));this.xhr[a].open("POST",this.target,!0);null!=g&&this.xhr[a].setRequestHeader("Authorization","Digest "+g);this.xhr[a].send(e)}};