fdfd
This commit is contained in:
parent
a4aaa6dec4
commit
714db2bf8a
1 changed files with 35 additions and 2 deletions
|
@ -645,6 +645,39 @@
|
||||||
|
|
||||||
// Voting
|
// Voting
|
||||||
|
|
||||||
|
function post_vote(url, callback) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", url, true);
|
||||||
|
var form = new FormData()
|
||||||
|
form.append("formkey", formkey());
|
||||||
|
xhr.withCredentials=true;
|
||||||
|
|
||||||
|
xhr.onload = function() {
|
||||||
|
if (xhr.status==204) {}
|
||||||
|
else if (xhr.status >= 200 && xhr.status < 300) {
|
||||||
|
$('#toast-post-success').toast('dispose');
|
||||||
|
$('#toast-post-success').toast('show');
|
||||||
|
document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"];
|
||||||
|
callback(xhr)
|
||||||
|
return true
|
||||||
|
|
||||||
|
} else if (xhr.status >= 300 && xhr.status < 400) {
|
||||||
|
window.location.href = JSON.parse(xhr.response)["redirect"]
|
||||||
|
} else {
|
||||||
|
data=JSON.parse(xhr.response);
|
||||||
|
|
||||||
|
$('#toast-post-error').toast('dispose');
|
||||||
|
$('#toast-post-error').toast('show');
|
||||||
|
document.getElementById('toast-post-error-text').innerText = data["error"];
|
||||||
|
return false
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send(form);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
var upvote = function(event) {
|
var upvote = function(event) {
|
||||||
|
|
||||||
var type = event.target.dataset.contentType;
|
var type = event.target.dataset.contentType;
|
||||||
|
@ -691,7 +724,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post("/vote/" + type + "/" + id + "/" + voteDirection);
|
post_vote("/vote/" + type + "/" + id + "/" + voteDirection);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,7 +774,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post("/vote/" + type + "/" + id + "/" + voteDirection);
|
post_vote("/vote/" + type + "/" + id + "/" + voteDirection);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue