ajax-hook icon indicating copy to clipboard operation
ajax-hook copied to clipboard

代理后,比axios原来的返回多了个xhr对象,导致对返回的response做JSON.stringnify处理报错

Open hzr5700 opened this issue 2 years ago • 3 comments

hzr5700 avatar Aug 24 '22 02:08 hzr5700

open: function open(args, xhr) { var _this = this; var config = xhr.config = {headers: {}}; config.method = args[0]; config.url = args[1]; config.async = args[2]; config.user = args[3]; config.password = args[4]; config.xhr = xhr;//这边在返回对象中引入了xhr,导致问题 var evName = 'on' + eventReadyStateChange; if (!xhr[evName]) { xhr[evName] = function () { return stateChangeCallback(xhr, _this); }; }

  // 如果有请求拦截器,则在调用onRequest后再打开链接。因为onRequest最佳调用时机是在send前,
  // 所以我们在send拦截函数中再手动调用open,因此返回true阻止xhr.open调用。
  //
  // 如果没有请求拦截器,则不用阻断xhr.open调用
  if (onRequest) return true;
},

hzr5700 avatar Sep 24 '22 06:09 hzr5700

open: function open(args, xhr) { var _this = this; var config = xhr.config = {headers: {}}; config.method = args[0]; config.url = args[1]; config.async = args[2]; config.user = args[3]; config.password = args[4]; config.xhr = xhr;//这边在返回对象中引入了xhr,导致问题 var evName = 'on' + eventReadyStateChange; if (!xhr[evName]) { xhr[evName] = function () { return stateChangeCallback(xhr, _this); }; }

  // 如果有请求拦截器,则在调用onRequest后再打开链接。因为onRequest最佳调用时机是在send前,
  // 所以我们在send拦截函数中再手动调用open,因此返回true阻止xhr.open调用。
  //
  // 如果没有请求拦截器,则不用阻断xhr.open调用
  if (onRequest) return true;
},

@hzr5700 能补充一下实际使用中的代码 case 吗?详细说明一下问题,以便跟进处理

YinanZhaoXometry avatar Oct 31 '22 09:10 YinanZhaoXometry

使用proxy代理后,然后再执行接口请求axios.get(url).then(response => {return JSON.parse(JSON.stringnify(response))});使用JSON.stringnify处理报错。代理代码:proxy({ //请求发起前进入 onRequest: (config, handler) => { this.domainFilter(config); handler.next(config); } });

hzr5700 avatar Nov 08 '22 11:11 hzr5700