forked from wayou/t-rex-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
41 lines (38 loc) 路 977 Bytes
/
Copy pathapi.js
File metadata and controls
41 lines (38 loc) 路 977 Bytes
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
function ajax_json(type, url, data, success_fn, failure_fn) {
let ajax_options = {
type: type,
url: url,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(resp){
if (success_fn) success_fn(resp);
},
failure: function(resp) {
if(failure_fn){
failure_fn(resp);
}
else {
alert('Something went wrong');
console.error('<ERROR>', resp);
}
},
};
if (data) ajax_options['data'] = JSON.stringify(data);
return $.ajax(ajax_options);
}
// API
const SCORE_API = './api/score.php';
// 1) list top 10
function list_top10(callback, q) {
let t = +(new Date());
let url = SCORE_API + '?q=' + q + '&t=' + t; // prevent cache
return ajax_json('GET', url, null, callback);
}
// 2) submit score
function dont_hack_me_bro(token_id, score) {
ajax_json('POST', SCORE_API, {
token_id: token_id,
score: score,
secret: "donothackmebro", // 馃ズ
});
}