求教:我在本地建立一个html文件,想获得网络数据,点击“上证指数”按钮成功,其他两个按钮失败。
<!DOCTYPE HTML><html>
<head>
<title>Cross Origin Test</title>
</head>
<script type="text/javascript">
var httpRequest;
function getFromNet(url)
{
httpRequest = null;
httpRequest = new XMLHttpRequest();
if (httpRequest != null)
{
httpRequest.onreadystatechange = handleResponse;
httpRequest.open("GET", url, true);
httpRequest.send();
}
}
function handleResponse()
{
if (httpRequest.readyState==4) // loaded
{
if (httpRequest.status==200) //OK
{
//alert(httpRequest.responseText);
document.getElementById("jieguo").value = httpRequest.responseText;
}
}
}
</script>
<body>
<button onclick = "getFromNet('http://qt.')">上证指数</button>
<button onclick = "getFromNet('https://hq.')">沪深股票列表</button>
<button onclick = "getFromNet('http://www.')">华能国际质押</button>
<p/>
<textarea id = jieguo style = "width:60em;height:20em"></textarea>
</body>
</html>