-
Notifications
You must be signed in to change notification settings - Fork 480
/
Copy pathapplication.js
39 lines (32 loc) · 1.39 KB
/
application.js
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
$(function() {
// just a super-simple JS demo
var demoHeaderBox;
// simple demo to show create something via javascript on the page
if ($('#javascript-header-demo-box').length !== 0) {
demoHeaderBox = $('#javascript-header-demo-box');
demoHeaderBox
.hide()
.text('Hello from JavaScript! This line has been added by public/js/application.js')
.css('color', 'green')
.fadeIn('slow');
}
// if #javascript-ajax-button exists
if ($('#javascript-ajax-button').length !== 0) {
$('#javascript-ajax-button').on('click', function(){
// send an ajax-request to this URL: current-server.com/songs/ajaxGetStats
// "url" is defined in views/_templates/footer.php
$.ajax(url + "/songs/ajaxGetStats")
.done(function(result) {
// this will be executed if the ajax-call was successful
// here we get the feedback from the ajax-call (result) and show it in #javascript-ajax-result-box
$('#javascript-ajax-result-box').html(result);
})
.fail(function() {
// this will be executed if the ajax-call had failed
})
.always(function() {
// this will ALWAYS be executed, regardless if the ajax-call was success or not
});
});
}
});