views:

20

answers:

1

HELP!! following code doesn't work! why?

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

Hey, finally I got the answer myself, I have post three questions since I started using stackoverflow, and none of them was answered by others other than myself. Hey, boss of the stackoverflow: can you come up with a new rewarding system, so people are more actively in answering questions?

in a nutshell, if your AJAX application is in the page http://www.yourserver.com/junk.html, then any XMLHttpRequest that comes from that page can only make a request to a web service using the domain www.yourserver.com.

see http://www.xml.com/pub/a/2005/11/09/fixing-ajax-xmlhttprequest-considered-harmful.html for detailed information.

Alex Zhou
nobody will answer you unless you accept the right answer.
Gabi Purcaru