-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlike-javascript.php
More file actions
38 lines (37 loc) · 943 Bytes
/
like-javascript.php
File metadata and controls
38 lines (37 loc) · 943 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
<script type="text/javascript">
function like(id) {
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
//
}
var param = "id="+id;
xmlhttp.open("POST","script-post-like.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", param.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(param);
var source=document.getElementById(id).src.replace(/^.*[\\\/]/, '');
var n=document.getElementById("like"+id);
var num=Number(n.innerHTML);
if(source=='thumbs-up-gray.png'){
document.getElementById(id).src='thumbs-up-green.png';
num=num+1;
n.innerHTML=num;
}
else{
document.getElementById(id).src='thumbs-up-gray.png';
num=num-1;
if(num>0){
n.innerHTML=num;
}
else{
n.innerHTML="";
}
}
}
</script>