diff --git a/package.json b/package.json index 419bb25..2ac437c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bytedo/fetch", - "version": "2.1.0", + "version": "2.1.1", "description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch", "main": "dist/index.js", "files": [ diff --git a/src/index.js b/src/index.js index cb4eaed..726f769 100644 --- a/src/index.js +++ b/src/index.js @@ -150,18 +150,19 @@ class _Request { /* -------------------------- 3»» 处理跨域 --------------------- */ try { + let crossDomain let $a = document.createElement('a') - $a.href = options.url + $a.href = options.url crossDomain = location.protocol !== $a.protocol || location.host !== $a.host $a = null - } catch (err) {} - if (crossDomain) { - if (options.credentials) { - this.xhr.withCredentials = true + if (crossDomain) { + if (options.credentials) { + this.xhr.withCredentials = true + } } - } + } catch (err) {} /* ------------- 4»» 根据method类型, 处理表单数据 ---------------- */