用于替代ajax的 fetch API

fetch is the new and easy api for js to make request to the server, it replaces XMLHttpRequest.

## Objects:

fetch, Request, Reponse, Headers

## Usage:

“`
fetch(‘/path/to/fetch’,
{method: ‘GET’}
).then(function (response) {
// process response;
return response.json(); // returns a json promise
return response.text(); // returns a text promise

return ret; // will be consumed in the next then funcion
}).then(function (data) {
// data is a json or text
// process
}).catch(function (err) {

// error handling
});
“`

notice, the useful method

Advanced:

About 逸飞

后端工程师

发表评论

电子邮件地址不会被公开。 必填项已用*标注