-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
90 lines (81 loc) · 2.82 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jquery.waterfall</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../jquery.waterfall.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
$('.waterfall').click(function(e) {
console.log('first');
// series of 3 request - always done
$.waterfall(
function() {
return $.ajax({ url : 'post.php?arg=1'});
},
function() {
return $.ajax({ url : 'post.php?arg='+(1+parseInt(arguments[0]))});
},
function() {
return $.ajax({ url : 'post.php?arg=3'});
},
function() {
return parseInt(arguments[0]) + parseInt(arguments[1]) + parseInt(arguments[2]);
}
)
.fail(function() {
console.log('error');
console.log(arguments)
$('.result').append('First waterfall failed. arguments number: '+arguments.length+'. Details see in console.<br>');
})
.done(function() {
console.log('success');
console.log(arguments)
$('.result').append('First waterfall success. arguments number: '+arguments.length+'. Details see in console.<br>');
});
console.log('second')
// check result after first request
$.waterfall(
function() {
return $.ajax({ url : 'post.php?ser=2&arg=1'});
},
function() {
return !(parseInt(arguments[0]) == 1);
},
function() {
return $.ajax({ url : 'post.php?ser=2&arg=3'});
}
)
.fail(function() {
console.log('error');
console.log(arguments)
$('.result').append('Second waterfall failed. arguments number: '+arguments.length+'. Details see in console.<br>');
})
.done(function() {
console.log('success');
console.log(arguments)
$('.result').text('Second waterfall success. arguments number: '+arguments.length+'. Details see in console.<br>');
});
// $.waterfall(
// f1, f2, f3, 'Most important question in the Universe.', {answer : 42}, null, void(0), $.ajax({ url : 'post.php?arg=4'})
// ).fail(function() {
// console.log('error');
// console.log(arguments);
// $('.result').text('waterfall failed. arguments number: '+arguments.length+'. Details see in console.');
// }).done(function() {
// console.log('success');
// console.log(arguments);
// $('.result').text('waterfall success. arguments number: '+arguments.length+'. Details see in console.');
// })
})
})
</script>
</head>
<body>
<button class="waterfall">waterfall</button>
<div class="result">
</div>
</body>
</html>