看板 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)
averywu:安全性設定javascript是不能存取用戶端檔案的 12/03 13:05
s25g5d4:設定dataType 12/03 18:45
danny0838:1F:您的意思是說chrome禁止讀檔才對,Fx IE Opera都不對? 12/03 21:29
danny0838:2F: 能請教詳細做法嗎?用哪個指令設定?設定成什麼? 12/03 21:29
s25g5d4:恩恩...看起來你是單機測試 先設定dataType:"text"試試 12/03 22:28
s25g5d4:如果不行就是如1F的講法了 12/03 22:28
s25g5d4:就是在type:"GET",下面在加一行dataType:"text", 12/03 22:28
danny0838:加了,還是不行.. 12/03 23:29
averywu:對不起我看錯了 12/03 23:30
s25g5d4:那就不知道了...基本上我是自己架apache來玩 12/03 23:38
kiwatami:你寫一個頁面去讀檔 把他output 再用ajax讀那個頁面 12/05 01:12
↑這段看不懂
buganini:看httpd log裡面.txt有沒有被request 看chrome developer 12/05 04:46
buganini:tool有沒有javascript的錯誤 12/05 04:46
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)
s25g5d4:正如1F所講的 chrome不給讀本機 12/07 18:59