parent
86136434ed
commit
48301ee0ec
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@bytedo/fetch",
|
"name": "@bytedo/fetch",
|
||||||
"version": "2.0.2",
|
"version": "2.1.0",
|
||||||
"description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch",
|
"description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|
|
@ -56,7 +56,6 @@ class _Request {
|
||||||
|
|
||||||
this.options = {
|
this.options = {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
|
||||||
'content-type': FORM_TYPES.form
|
'content-type': FORM_TYPES.form
|
||||||
},
|
},
|
||||||
body: null,
|
body: null,
|
||||||
|
@ -94,7 +93,6 @@ class _Request {
|
||||||
var options = this.options
|
var options = this.options
|
||||||
var params = null
|
var params = null
|
||||||
var hasAttach = false // 是否有附件
|
var hasAttach = false // 是否有附件
|
||||||
var crossDomain = false // 是否跨域
|
|
||||||
var noBody = NOBODY_METHODS.includes(options.method)
|
var noBody = NOBODY_METHODS.includes(options.method)
|
||||||
|
|
||||||
/* ------------------------ 1»» 处理signal ---------------------- */
|
/* ------------------------ 1»» 处理signal ---------------------- */
|
||||||
|
@ -162,8 +160,6 @@ class _Request {
|
||||||
if (crossDomain) {
|
if (crossDomain) {
|
||||||
if (options.credentials) {
|
if (options.credentials) {
|
||||||
this.xhr.withCredentials = true
|
this.xhr.withCredentials = true
|
||||||
} else {
|
|
||||||
delete options.headers['X-Requested-With']
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
src/next.js
13
src/next.js
|
@ -46,7 +46,6 @@ class _Request {
|
||||||
|
|
||||||
this.options = {
|
this.options = {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
|
||||||
'content-type': FORM_TYPES.form
|
'content-type': FORM_TYPES.form
|
||||||
},
|
},
|
||||||
body: null,
|
body: null,
|
||||||
|
@ -78,7 +77,6 @@ class _Request {
|
||||||
__next__() {
|
__next__() {
|
||||||
var options = this.options
|
var options = this.options
|
||||||
var hasAttach = false // 是否有附件
|
var hasAttach = false // 是否有附件
|
||||||
var crossDomain = false // 是否跨域
|
|
||||||
var noBody = NOBODY_METHODS.includes(options.method)
|
var noBody = NOBODY_METHODS.includes(options.method)
|
||||||
|
|
||||||
/* -------------------------- 1»» 请求的内容 --------------------- */
|
/* -------------------------- 1»» 请求的内容 --------------------- */
|
||||||
|
@ -127,17 +125,6 @@ class _Request {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------- 2»» 处理跨域 --------------------- */
|
/* -------------------------- 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类型, 处理表单数据 ---------------- */
|
/* ------------- 3»» 根据method类型, 处理表单数据 ---------------- */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue