3 lines
No EOL
1 KiB
JavaScript
3 lines
No EOL
1 KiB
JavaScript
function promiseXHR(a,b,g){var n="XMLHttpRequest",h="setRequestHeader",k="constructor",t="hasOwnProperty",u="POST",v="content-type",w="x-requested-with",x=Object,y=function(d){return encodeURIComponent(d).replace(/%20/g,"+")},c,e,f,l,z,m;
|
|
if(b)switch(b[k]){case self.FormData:l=1;break;case x:for(p in m="_="+(new Date).getTime(),b)if(b[t](p))for(b[p]&&b[p][k]==Array||(b[p]=[b[p]]),c=0;c<b[p].length;c++)m+="&"+y(p)+"="+y(b[p][c]);case Number:g=g||b,b=m}switch(a[k]){case x:e=a.method,f=a.headers,a=a.url;case String:c=a||location.href.split("#")[0];(e=e||(b?u:"GET"))in{GET:1,HEAD:1}&&b&&(c+=(0>c.indexOf("?")?"?":"&")+b);a=new self[n];
|
|
a.open(e,c);for(p in f)f[t](p)&&(a[h](c=p.toLowerCase(),f[p]),c==v&&(l=1),c==w&&(z=1));z||a[h](w,n);l||e==u&&a[h](v,"application/x-www-form-urlencoded")}return new Promise(function(A,B){a.onreadystatechange=function(){4==a.readyState&&A(a)};g|0&&setTimeout(function(){B("timeout");a.abort()},g);a.send(b)})}self.Promise||document.write("<script src=//cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js></script>") |