[問題] Chrome無法用Ajax讀取本機檔案
記得以前的版本可以,但自從Chrome改到某一版就不能用了,
不知此功能是被Chrome限制了,或是我疏忽了什麼設定?
(我用的版本是Chrome 8.0.552.215)
以下是測試程式碼,Chrome以外的IE, Fx, Opera都能讀到檔案內容:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>Hello! Ajax! Examples...</title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
function startRequest(){
var s = $.ajax({
url: "HelloAjaxEx-1.txt",
type:"GET",
success:function(msg){
alert(msg);
}
});
}
</script>
</head>
<body>
<center>
<input value="Ajax請求" onclick="startRequest();" type="button">
</center>
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 119.14.182.86
※ 編輯: danny0838 來自: 119.14.182.86 (12/03 11:14)
→
12/03 13:05, , 1F
12/03 13:05, 1F
推
12/03 18:45, , 2F
12/03 18:45, 2F
→
12/03 21:29, , 3F
12/03 21:29, 3F
→
12/03 21:29, , 4F
12/03 21:29, 4F
→
12/03 22:28, , 5F
12/03 22:28, 5F
→
12/03 22:28, , 6F
12/03 22:28, 6F
→
12/03 22:28, , 7F
12/03 22:28, 7F
→
12/03 23:29, , 8F
12/03 23:29, 8F
→
12/03 23:30, , 9F
12/03 23:30, 9F
→
12/03 23:38, , 10F
12/03 23:38, 10F
推
12/05 01:12, , 11F
12/05 01:12, 11F
↑這段看不懂
→
12/05 04:46, , 12F
12/05 04:46, 12F
→
12/05 04:46, , 13F
12/05 04:46, 13F
1.我要的是離線執行的程式,不是在本機架server再用local連入,所以沒httpd。
2.Chrome 有錯誤訊息:
XMLHttpRequest cannot load file:///E:/(中略)/HelloAjaxEx-1.txt.
Origin null is not allowed by Access-Control-Allow-Origin.
※ 編輯: danny0838 來自: 119.14.182.86 (12/07 14:41)
→
12/07 18:59, , 14F
12/07 18:59, 14F