【问题标题】:innerhtml not working on bloggerinnerhtml 在博客上不起作用
【发布时间】:2012-04-08 17:24:48
【问题描述】:

我正在开发一个简单的投票系统。当两个文件在一起(本地)时,它可以正常工作。

但是,当我在博客上发布它时,它无法输出结果。 (点击投票在虚拟主机上注册,但结果不显示!)

这是我的代码:

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

【问题讨论】:

    标签: javascript ajax innerhtml blogger


    【解决方案1】:

    不是innerHTML 不起作用。这是您对外部站点的调用。您不能使用 XMLHttpRequest 从域外获取资源:它被称为跨域限制,并且内置于浏览器规范中。

    当 PHP 托管在与 GETs 的代码相同的域时,它可以工作,因为这不是跨域的。

    您可以通过在您的域上使用 代理脚本 来绕过限制:页面从该服务器端脚本请求结果,该脚本从真实位置获取结果,并返回该结果到浏览器。

    这不太可能是 Blogger 的选项,因此 Blogger 提供their own poll widget

    【讨论】:

    • 非常感谢安德鲁!换句话说,拥有我自己的网络托管服务就可以完成这项工作吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 2018-12-29
    • 2015-12-19
    • 2018-05-24
    • 1970-01-01
    相关资源
    最近更新 更多