From 48301ee0ec1bf07ccf46c75897da19b738a36d64 Mon Sep 17 00:00:00 2001 From: yutent Date: Sun, 16 Oct 2022 22:47:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4X-Requested-With?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.js | 4 ---- src/next.js | 13 ------------- 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/package.json b/package.json index a373491..419bb25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bytedo/fetch", - "version": "2.0.2", + "version": "2.1.0", "description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch", "main": "dist/index.js", "files": [ diff --git a/src/index.js b/src/index.js index ea6925e..cb4eaed 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,6 @@ class _Request { this.options = { headers: { - 'X-Requested-With': 'XMLHttpRequest', 'content-type': FORM_TYPES.form }, body: null, @@ -94,7 +93,6 @@ class _Request { var options = this.options var params = null var hasAttach = false // 是否有附件 - var crossDomain = false // 是否跨域 var noBody = NOBODY_METHODS.includes(options.method) /* ------------------------ 1»» 处理signal ---------------------- */ @@ -162,8 +160,6 @@ class _Request { if (crossDomain) { if (options.credentials) { this.xhr.withCredentials = true - } else { - delete options.headers['X-Requested-With'] } } diff --git a/src/next.js b/src/next.js index 01f851b..a0936c1 100644 --- a/src/next.js +++ b/src/next.js @@ -46,7 +46,6 @@ class _Request { this.options = { headers: { - 'X-Requested-With': 'XMLHttpRequest', 'content-type': FORM_TYPES.form }, body: null, @@ -78,7 +77,6 @@ class _Request { __next__() { var options = this.options var hasAttach = false // 是否有附件 - var crossDomain = false // 是否跨域 var noBody = NOBODY_METHODS.includes(options.method) /* -------------------------- 1»» 请求的内容 --------------------- */ @@ -127,17 +125,6 @@ class _Request { } /* -------------------------- 2»» 处理跨域 --------------------- */ - try { - let $a = document.createElement('a') - $a.href = options.url - - crossDomain = location.protocol !== $a.protocol || location.host !== $a.host - $a = null - } catch (err) {} - - if (crossDomain && options.credentials === 'omit') { - delete options.headers['X-Requested-With'] - } /* ------------- 3»» 根据method类型, 处理表单数据 ---------------- */