问题
I'm working on a simple vote system. It works fine when the two files are together(locally).
However, when I publish it on blogger, it is unable to output the results. (on click the vote gets registered on the webhost, but the results just don't show!)
heres my code:
<script type="text/javascript">
function getVote(int)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("poll").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://pacontest.eu.pn/poll_vote.php?vote="+int,true);
xmlhttp.send();
}
</script>
<div id="poll">
<h3>Do you like this?</h3>
<form>
Yes:
<input type="radio" name="vote" value="0" onclick="getVote(this.value)" />
No:
<input type="radio" name="vote" value="1" onclick="getVote(this.value)" />
</form>
</div>
回答1:
It's not innerHTML
that's not working. It's your call to an external site. You can't use XMLHttpRequest to get a resource from outside your domain: it's called a cross-domain restriction and is built into browser specifications.
It works when the PHP is hosted on the same domain as the code which GET
s it, because that's not cross-domain.
You can get round the restriction by using a proxy script on your domain: the page requests the result from that server-side script and that script gets the result from the true location, returning that result to the browser.
That's not likely to be an option for Blogger, so Blogger provide their own poll widget.
来源:https://stackoverflow.com/questions/10064773/innerhtml-not-working-on-blogger