/
index.html.erb
44 lines (39 loc) · 945 Bytes
/
index.html.erb
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
<h1>Show Page</h1>
<h2>Loaded Tasks: <span id="loaded">0</span></h1>
<h2>Total Tasks: <%= @length %></h2>
<% if @tasks %>
<table>
<tr id="loading">
<td>Loading Data...</td>
</tr>
</table>
<script type="text/javascript">
$(function(){
var len = <%= @length %>;
var count = 1;
alert("Document Ready.");
$.ajaxSetup({
complete: function(){
alert("Ajax " + count + " Complete.");
if(count <= len){
alert("Condition == true, incrementing count, calling next ajax call.");
count++;
getData();
}
else
$("#loading").remove();
}
})
function getData(){
//console.log("Started " + count);
alert("Start Ajax " + count + " call.");
$.get('/increment?task=' + count, function(data){
$("<tr></tr>").html(data.task).insertBefore("#loading");
//console.log("Finished " + data.task);
});
// Hi Stef :p
}
getData();
})
</script>
<% end %>