0

以下代码适用于 IE8,但不适用于 google chrome。我需要在代码中添加/修改以使其也可以与 chrome 一起使用。我听说过http://en.wikipedia.org/wiki/Same_origin_policyhttp://en.wikipedia.org/wiki/Cross-origin_resource_sharing

function clickMe()
{

    var xmlHttp = null;
   var Url = "http://www.w3schools.com/ajax/gethint.asp?q=u";
    //var Url = "file:///D:/Durgesh/test.html";
    xmlHttp = new XMLHttpRequest();    
    xmlHttp.onreadystatechange = function()
    {

        if ( xmlHttp.readyState == 4 )
        {
                alert("status Code: " + xmlHttp.status);
            if ( xmlHttp.responseText == "Not found" )
            {
                alert("Not Found");
            }
            else
            {
                alert(xmlHttp.responseText);
            }
        }
    }
    xmlHttp.open( "GET", Url, true );
    xmlHttp.setRequestHeader('Access-Control-Allow-Origin', '*'); 
    xmlHttp.send( null );

}
4

1 回答 1

0

Access-Control-Allow-Origin 必须是服务器端。;)

于 2012-08-06T10:52:19.163 回答