删除X-Requested-With

master 2.1.0
yutent 2022-10-16 22:47:22 +08:00
parent 86136434ed
commit 48301ee0ec
3 changed files with 1 additions and 18 deletions

View File

@ -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": [

View File

@ -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']
}
}

View File

@ -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类型, 处理表单数据 ---------------- */