fetch(url/request[, options])
var request = new Request(url/request[, options]);
fetch is a method of globals window request is a Request object, the same parameters and Request fetch parameter options is an object, the main key as follows:
1 2 3 4 5 6 7 8 9 10 11
method: GET / POST, etc. headers: a normal object, or a Headers target body: data passed to the server, may be a string / Buffer / Blob / FormData, if the method is GET / HEAD, can not have this parameter mode: cors / no-cors / same-origin , whether cross-domain, CORS-default is NO Credentials: The omit / Origin-Same, / the include Cache: default / NO-Store / reload / NO-Cache / Cache-Force / only-iF-cached the redirect: Follow / error / Manual the referrer: NO-the referrer / Client / or a URL referrerPolicy: the referrer-NO / NO-When-the referrer-downgrade / Origin / Origin-When-Cross-Origin / URL-the unsafe integrity: resource integrity verify fetch () returns a promise, so use it
Promises fetch API used to process the results / callback
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
fetch('/some/url').then(function(response) {
.}) the catch ( function ( ERR ) { // an error occurred; then equivalent to the second parameter, but this is more intuitive :( });
// chaining, asynchronous single thread becomes similar wording: Advanced Usage FETCH ( '/ some / URL' ) .then ( function ( Response ) { return // ... executed successfully, step 1 .. . }). the then ( function ( returnedValue ) { // ... executed successfully, step ... 2 }). the catch ( function ( ERR ) { // an error anywhere midway ... in this process :( } );
var blob = new Blob(dataArr:Array<any>, opt:{type:string}); //dataArray:数组,包含了要添加到Blob对象中的数据,数据可以是任意多个ArrayBuffer,ArrayBufferView, Blob,或者 DOMString对象。 //opt:对象,用于设置Blob对象的属性(如:MIME类型)