[問題] XMLHttpRequest 範例
小弟爬了之前的文章 照著下面的網址作了一個簡單的程式
https://developer.mozilla.org/En/Using_XMLHttpRequest
結果 xmlhttp.status 總是傳回 0
用 firebug 還看到如下可怕的 error :
uncaught exception: [Exception... "Component returned failure code:
0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005
(NS_ERROR_FAILURE)" location: "JS frame :: http://localhost/test.html ::
dumpPage :: line 18" data: no]
懇請各位大大幫忙看一下怎麼回事 謝謝
測試程式如下 :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"" rel="nofollow">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Dump webpage</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function dumpPage() {
document.getElementById('theExample').innerHTML = 'start dump
page';
if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=raw;
str = "http://www.mozilla.org/";
xmlhttp.open("GET", str, true);
xmlhttp.send(null);
}
}
function raw() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
document.getElementById('theExample').innerHTML=xmlhttp.responseText;
}
}
}
</script>
</head>
<body>
<div id="theExample">Loading...</div>
<br/>
<br/>
<input type="button" onclick="dumpPage()" value="Dump Page" />
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 98.234.115.90
→
12/31 10:12, , 1F
12/31 10:12, 1F
→
12/31 10:13, , 2F
12/31 10:13, 2F
→
12/31 10:13, , 3F
12/31 10:13, 3F
→
12/31 10:14, , 4F
12/31 10:14, 4F
→
12/31 10:14, , 5F
12/31 10:14, 5F
→
12/31 10:16, , 6F
12/31 10:16, 6F
→
12/31 10:16, , 7F
12/31 10:16, 7F
→
12/31 10:17, , 8F
12/31 10:17, 8F
→
12/31 10:17, , 9F
12/31 10:17, 9F
→
12/31 13:08, , 10F
12/31 13:08, 10F
→
12/31 13:09, , 11F
12/31 13:09, 11F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章