我有一个简单的投票系统来处理 2 个 php 文件。但是,它不适用于博主(prolly 因为现在 1 个文件是 HTML)
更具体地说,投票结果在我的数据库中注册。它只是无法输出响应。
这是我的代码:
<div id="poll" style="width:200px;overflow:hidden;text-align:center;">
Do you like this poll?
<div style="text-align:left;width:180px;margin:0 auto;">
<input type="radio" name="poll" id="poll1" checked>Yes, it`s great
<input type="radio" name="poll" id="poll2">Yes...
<input type="radio" name="poll" id="poll3">Not bad...
<input type="radio" name="poll" id="poll4">No!
</div>
<input type="button" value="Vote!" onClick="vote();"/>
</div>
<script type="text/javascript">
function vote(){
for(var i=1;i<=4;i++){
if(document.getElementById('poll' + i).checked){
//Check which one has been checked
var sendto = 'http://myhostingadd.com/vote.php?vote=' + i;
}
}
// Call the vote.php file
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest;
xmlhttp.open("GET",sendto,false);
xmlhttp.send(null);
}
else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET",sendto,false);
xmlhttp.send();
}
//Output the response
document.getElementById('poll').innerHTML = xmlhttp.responseText;
}
</script>