求教:想用html5改写程序,点击按钮,获得网页数据,好像遇到了跨域问题。
<!DOCTYPE HTML><html>
<head>
<title>Cross Origin Test</title>
</head>
<script>
function getFromNet(){
alert("here is me");
var httpRequest = new XMLHttpRequest();
var url = "http://qt.
alert(url);
httpRequest.onreadystatechange = handleResponse;
httpRequest.open("GET", url);
httpRequest.response.setHeader("Access-Control-Allow-Origin","*");
httpRequest.response.setHeader("Access-Control-Allow-Methods","GET");
httpRequest.response.setHeader("Access-Control-Allow-Headers","x-requested-with,content-type");
httpRequest.send();
}
function handleResponse(){
alert("here");
alert(httpRequest.responseText);
}
</script>
<body>
<button onclick = "getFromNet()">ClickMe</button>
</body>
</html>