【问题标题】:google map api with AJAX call doesn't work带有 AJAX 调用的谷歌地图 api 不起作用
【发布时间】:2011-02-20 17:28:25
【问题描述】:

帮助!!以下代码不起作用!为什么?

 <html>
    <head>
    <script type="text/javascript">
    function loadXMLDoc()
    {
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      alert("aa");
      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("myDiv").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","http://maps.google.com/maps/geo?q=hangzhou",true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>

    <div id="myDiv"><h2>Let AJAX change this text</h2></div>
    <button type="button" onclick="loadXMLDoc()">Change Content</button>

    </body>
    </html>

【问题讨论】:

    标签: ajax google-maps


    【解决方案1】:

    嘿,终于我自己得到了答案,自从我开始使用stackoverflow以来,我已经发布了三个问题,除了我自己之外,其他人都没有回答。嘿,stackoverflow 的老大:你能想出一个新的奖励系统,让人们更积极地回答问题吗?

    简而言之,如果您的 AJAX 应用程序位于页面 http://www.yourserver.com/junk.html 中,那么来自该页面的任何 XMLHttpRequest 都只能使用域 www.yourserver.com 向 Web 服务发出请求。

    http://www.xml.com/pub/a/2005/11/09/fixing-ajax-xmlhttprequest-considered-harmful.html 了解详细信息。

    【讨论】:

    • 非常感谢,您为我节省了一天的时间!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多