forked from arkbg1/BitVote
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathajax.js
More file actions
46 lines (40 loc) · 1.35 KB
/
ajax.js
File metadata and controls
46 lines (40 loc) · 1.35 KB
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
//echo "$time_str <a href='http://$url'>http://$url</a>\n";
function new_request() {
if (window.XMLHttpRequest)
return new XMLHttpRequest();
else
return new ActiveXObject("Microsoft.XMLHTTP");
}
function register_callback(xmlhttp, _func){
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
var res = JSON.parse(xmlhttp.responseText);
_func(res);
}
}
}
function make_request(xmlhttp, method, path, async, params){
xmlhttp.open(method, path, async);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var s = "", i = 0;
for (var k in params){
if (i > 0)
s += "&";
s += k+"="+encodeURIComponent(params[k]);
i++;
}
//xmlhttp.setRequestHeader("Content-length", s.length);
xmlhttp.send(s);
}
function lookup_user(usr_id, cur_time){
xmlhttp = new_request();
register_callback(xmlhttp, _lookup_user);
make_request(xmlhttp, "POST", 'ajax/lookup_user.php', true, {"usr_id":usr_id, "cur_time":cur_time});
return false;
}
function cast_vote(url, spent, usr_id){
xmlhttp = new_request();
register_callback(xmlhttp, _cast_vote);
make_request(xmlhttp, "POST", 'ajax/cast_vote.php', true, {"url":url, "usr_id":usr_id, "time_spent":spent, "time_reg":reg_time});
return false;
}