forked from rDrama/rDrama
fdfd
parent
d1b640d33c
commit
1540ea41bd
|
@ -645,6 +645,39 @@
|
|||
|
||||
// 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 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…
Reference in New Issue