2010-08-28 99 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