innerhtml无法在Blogger上使用 [英] innerhtml not working on blogger

查看:61
本文介绍了innerhtml无法在Blogger上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个简单的投票系统.当两个文件(本地)在一起时,效果很好.

I'm working on a simple vote system. It works fine when the two files are together(locally).

但是,当我在Blogger上发布它时,它无法输出结果. (单击后,投票将在虚拟主机上注册,但结果不会显示!)

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!)

这是我的代码:

<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>

推荐答案

不是innerHTML无效.这是您打给外部站点的电话.您不能使用XMLHttpRequest从域外获取资源:这称为跨域限制,并且内置于浏览器规范中.

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.

当PHP与GET所在的代码位于同一域中时,它可以工作,因为它不是跨域的.

It works when the PHP is hosted on the same domain as the code which GETs 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.

Blogger不太可能选择该选项,因此Blogger提供了

That's not likely to be an option for Blogger, so Blogger provide their own poll widget.

这篇关于innerhtml无法在Blogger上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆