【发布时间】:2014-11-02 13:02:03
【问题描述】:
到目前为止,当在评论下方单击此表单时,我可以提交支持。我已尽可能将其设为伪代码,以避免过于本地化的问题:
<form id="upvote" method=post action="/comment_upvote">
<input type="hidden" name="cid" value=%cid></input>
<input type="hidden" name="bpid" value=%bpid></input>
...
<input type="submit" value="">
</form>
这个 Javascript xmlhttp 代码来处理它
var upvote = document.getElementById("upvote");
upvote.onclick = function(event) {
event.preventDefault();
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST", "http://localhost/comment_upvote", true)
xmlhttp.send()
}
我觉得这不是最好的方式,尤其是在谈论使用完整的 POST 表单来处理投票时。
我的问题是:有什么更好、更易读的方式来发布这个投票表单?
【问题讨论】:
标签: javascript forms post xmlhttprequest