0
<html>
<body>
<SCRIPT type="text/javascript">
var xmlHttp = new XMLHttpRequest();
var async = true;
xmlHttp.open("GET", "http://www.google.com", async);
if(async)
{
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
if (xmlHttp.status==200) alert("It works!")
else if (xmlHttp.status==0) alert("Arggggg!")
else alert("Status is "+xmlHttp.status)
}
}
}
xmlHttp.send();
</script>
</body>
</html>
我只是好奇XMLHttpRequest來查看它並正常工作,但我無法獲得狀態爲非零。這些例子看起來很簡單,但它不起作用。我已經嘗試了大約4個例子。有沒有搞錯 ?XMLHttpRequest簡單的HTTP GET不工作?
我想要做的就是讀取網頁並以純文本格式查看HTML。
就是這樣。這是一個用你的代碼返回一個404的例子:http://jsfiddle.net/dFyjt/ – Andir 2010-07-14 13:48:31