2010-08-28 96 views
0

帮助!以下代码不起作用!为什么?谷歌地图API与AJAX调用不起作用

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

回答

0

嘿,我终于得到了自己的答案,我有后三个问题,因为我开始使用计算器,和他们没有被别人除了我自己回答。嘿,老大的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

+0

没有人会回答你,除非你接受正确的答案。 – 2010-08-29 11:06:10

+0

非常感谢你,你救了我一天! – 2011-02-20 12:48:29