JSFiddle - React, Tailwind, and code Playground
by yakun chen
HTML
管道
JavaScript
// 在JavaScript 中常常无法便捷地执行一系列异步任务,
// 一个主要原因是无法在第一个任务结束之前就向第二个任务附加处理器。
/*
var getPromise = $.get('/query');
getPromise.done(function (data) {
var postPromise = $.post('/search', data);
});
*/
// pipe 最多能接受3 个参数,它们对应着Promise 对象的3 种回调类型:
// done、fail 和 progress
var getPromise = $.get('/echo/json');
var postPromise = getPromise.pipe(function (data) {
console.log(data);
alert('on success');
return $.post('/echo/xml', data);
}, function () {
alert('on fail');
}, function () {
alert('on progress');
});