@@ -13,22 +13,27 @@ import util from "./util.js";
1313
1414/**
1515 * 请求方式(OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, PATCH)
16+ * https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods
1617 *
1718 * @type {{TRACE: string, HEAD: string, DELETE: string, POST: string, GET: string, PATCH: string, OPTIONS: string, PUT: string} }
1819 */
1920const METHOD = {
20- OPTIONS : "OPTIONS" ,
2121 GET : "GET" ,
2222 HEAD : "HEAD" ,
2323 POST : "POST" ,
2424 PUT : "PUT" ,
2525 DELETE : "DELETE" ,
26+ CONNECT : "CONNECT" ,
27+ OPTIONS : "OPTIONS" ,
2628 TRACE : "TRACE" ,
27- PATCH : "PATCH"
29+ PATCH : "PATCH" ,
2830}
2931
3032/**
3133 * Content-Type请求数据类型,告诉接收方,我发什么类型的数据。
34+ * https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Type
35+ * https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types
36+ * https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Disposition
3237 *
3338 * application/x-www-form-urlencoded:数据被编码为名称/值对。这是标准的编码格式。默认使用此类型。
3439 * multipart/form-data:数据被编码为一条消息,页上的每个控件对应消息中的一个部分。
@@ -42,18 +47,7 @@ const CONTENT_TYPE = {
4247
4348/**
4449 * XMLHttpRequest预期服务器返回数据类型,并根据此值进行本地解析
45- *
46- * "" 将 responseType 设为空字符串与设置为"text"相同, 是默认类型 (实际上是 DOMString)。
47- * "arraybuffer" response 是一个包含二进制数据的 JavaScript ArrayBuffer 。
48- * "blob" response 是一个包含二进制数据的 Blob 对象 。
49- * "document" response 是一个 HTML Document 或 XML XMLDocument ,这取决于接收到的数据的 MIME 类型。
50- * "json" response 是一个 JavaScript 对象。这个对象是通过将接收到的数据类型视为 JSON 解析得到的。
51- * "text" response 是包含在 DOMString 对象中的文本。
52- * "moz-chunked-arraybuffer" 与"arraybuffer"相似,但是数据会被接收到一个流中。
53- * 使用此响应类型时,响应中的值仅在 progress 事件的处理程序中可用,并且只包含上一次响应 progress 事件以后收到的数据,
54- * 而不是自请求发送以来收到的所有数据。在 progress 事件处理时访问 response 将返回到目前为止收到的数据。
55- * 在 progress 事件处理程序之外访问, response 的值会始终为 null 。
56- * "ms-stream" response 是下载流的一部分;此响应类型仅允许下载请求,并且仅受Internet Explorer支持。
50+ * https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/responseType
5751 *
5852 * @type {{ARRAY_BUFFER: string, BLOB: string, MS_STREAM: string, DOCUMENT: string, TEXT: string, JSON: string} }
5953 */
@@ -63,7 +57,7 @@ const RESPONSE_TYPE = {
6357
6458
6559/**
66- * js封装ajax请求
60+ * js封装ajax请求 https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest
6761 * 使用new XMLHttpRequest 创建请求对象,所以不考虑低端IE浏览器(IE6及以下不支持XMLHttpRequest)
6862 * 注意:请求参数如果包含日期类型.是否能请求成功需要后台接口配合
6963 *
@@ -80,7 +74,7 @@ const ajax = (settings = {}) => {
8074 // 初始化请求参数
8175 let config = Object . assign ( {
8276 url : '' ,
83- method : settings . type || settings . method || ' GET' , // string 'GET' 'POST' 'DELETE'
77+ method : settings . type || settings . method || METHOD . GET ,
8478 // string 期望的返回数据类型:'json' 'text' 'document' ...
8579 responseType : settings . dataType || settings . responseType || RESPONSE_TYPE . JSON ,
8680 async : true , // boolean true:异步请求 false:同步请求 required
0 commit comments