-1

我有一个简单的投票系统来处理 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>
4

2 回答 2

1

您的sendto变量在 for 循环中本地声明。

于 2012-04-08T10:54:48.410 回答
0

我相信这与innerhtml not working on blogger是同一个问题,它不工作的原因是因为 XMLHttpRequest 的目标必须在同一个域上。一旦代码被移植到 Blogger,它就会中断。(关于另一个问题的完整答案)

于 2012-04-08T20:04:21.160 回答