This repository has been archived by the owner on May 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
95 lines (86 loc) · 2.71 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function myfn() {
//$('.likeform').submit(function () {
var likelems = document.getElementsByClassName('likeform');
for (var i = 0; i < likelems.length; i++) {
likelems[i].onsubmit = function (formdata) {
var request = new XMLHttpRequest();
request.open('POST', '/like.php', true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.onload = function () {
if (request.status >= 200 && request.status < 400) {
var resp = request.responseText;
data = JSON.parse(resp);
if (data['state'] == 1) {
document.getElementById('likebtn' + data['pid']).style.backgroundColor = 'red';
//$('#likebtn' + data['pid']).css('background-color', 'red');
}
else if (data['state'] == -1) {
document.getElementById('likebtn' + data['pid']).style.backgroundColor = 'white';
//$('#likebtn' + data['pid']).css('background-color', 'white');
}
document.getElementById('liketxt' + data['pid']).innerHTML = data['newval'] + " ♥";
//$('#liketxt' + data['pid']).text(data['newval'] + " ♥");
}
};
request.send(new URLSearchParams(new FormData(formdata['target'])).toString());
/*
$.ajax({
url: '/like.php',
type: 'post',
data: $(this).serialize(),
success: function (data) {
data = JSON.parse(data);
console.log(data);
if (data['state'] == 1)
{
$('#likebtn' + data['pid']).css('background-color', 'red');
}
else if (data['state'] == -1)
{
$('#likebtn' + data['pid']).css('background-color', 'white');
}
$('#liketxt' + data['pid']).text(data['newval'] + " ♥");
}
});
*/
return false;
};
}
//$('.commform').submit(function () {
var commelems = document.getElementsByClassName('commform');
for (var i = 0; i < commelems.length; i++) {
commelems[i].onsubmit = function (formdata) {
var request = new XMLHttpRequest();
request.open('POST', '/comment.php', true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.onload = function () {
if (request.status >= 200 && request.status < 400) {
window.location.reload();
}
};
request.send(new URLSearchParams(new FormData(formdata['target'])).toString());
/*
$.ajax({
url: '/comment.php',
type: 'post',
data: $(this).serialize(),
success: function (data) {
console.log(data);
window.location.reload();
}
});
*/
return false;
};
}
}
function ready(fn) {
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
//$(document).ready(
//);
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
ready(myfn);