gp更新来的太快
Posted allofalan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gp更新来的太快相关的知识,希望对你有一定的参考价值。
意外总是会发生
添加一个判断function的分支,过滤掉function,其实也考虑再进一步去分析它的作用,稍后再议。
更新一下
var gnp = { get: function(url) { return this._get(url, true) }, synget: function(url) { return this._get(url, false) }, _get: function(url, syn) { const promise = new Promise(function(resolve, reject) { const handler = function() { if(this.readyState !== 4) { return; } if(this.status === 200) { resolve(this.response); } else { reject(new Error(this.statusText)); } } var request = new XMLHttpRequest() request.open(‘GET‘, url, syn) request.onreadystatechange = handler request.send(null) }) return promise }, post: function(url, data) { return this._post(url, data, true) }, synpost: function(url, data) { return this._post(url, data, false) }, _post: function(url, data, syn) { const promise = new Promise(function(resolve, reject) { const handler = function() { if(this.readyState !== 4) { return; } if(this.status === 200) { resolve(this.response); } else { reject(new Error(this.statusText)); } } var request = new XMLHttpRequest() request.open(‘POST‘, url, syn) request.setRequestHeader("Content-Type","application/x-www-form-urlencoded") request.onreadystatechange = handler var ret = gnp._trans(data) request.send(ret.substr(0,ret.length-1)) }) return promise }, _trans : function(data,key = ‘‘){ var ret = "" if(typeof data == ‘object‘){ for(let it in data){ ret += gnp._trans(data[it],key + (key == ‘‘?it:"["+ it + "]")) } }else if(Array.isArray(data)){ for(var i = 0;i < data.length;i++){ ret += gnp._trans(data[i],key + "[" + i + "]") } }else if(typeof data == ‘function‘){ }else{ console.log(data) ret +=encodeURIComponent( key) + ‘=‘ + encodeURIComponent(data) + "&" } return ret } }
以上是关于gp更新来的太快的主要内容,如果未能解决你的问题,请参考以下文章