Re: [問題] 一個 JS 的系統問題

看板Ajax作者 (道可道非常道)時間15年前 (2009/01/15 10:59), 編輯推噓0(009)
留言9則, 2人參與, 最新討論串2/7 (看更多)
: → fillano:ajax可以在本機操作,但是ff3需要用about:config改權限 01/13 11:57 在下用 IE 在本機實測結果是不行, Fx 不知道要改哪一個 config,不過如果 IE 不行的話,在下就不考慮了。 放上伺服器的話,IE 和 Fx 都測過可以。 測試檔: HelloAjaxEx-1.txt 這是非同步請求的回應文字 HelloAjaxEx-1.js var xmlHttp; function createXMLHttpRequest() { if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } else if(window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } function startRequest() { createXMLHttpRequest(); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.open("GET", "HelloAjaxEx-1.txt"); xmlHttp.send(null); } function handleStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { alert("伺服端回應:" + xmlHttp.responseText); } } } HelloAjaxEx-1.html <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html; charset=Big5" http-equiv="content-type"> <title>Hello! Ajax! Examples...</title> <script type="text/javascript" src="HelloAjaxEx-1.js"></script> </head> <body> <center><input value="Ajax請求" onclick="startRequest();" type="button"></center> </body> </html> (↑按下綠色的按鈕執行) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.25.118.142

01/15 11:29, , 1F
ie會阻擋所有本機執行的html檔的javascript,不只是ajax
01/15 11:29, 1F

01/15 11:30, , 2F
簡單繞過的方法:把副檔名改成hta即可
01/15 11:30, 2F

01/15 11:37, , 3F
IE 是會擋 js,但是按下允許就好了呀...
01/15 11:37, 3F

01/15 11:38, , 4F
副檔名改成 hta 試過,還是在 xmlHttp.open 被拒
01/15 11:38, 4F

01/15 15:32, , 5F
把status==200判斷拿掉試試看。access本地檔案,永遠是0喔
01/15 15:32, 5F

01/15 21:03, , 6F
拿掉了還是不行...
01/15 21:03, 6F

01/15 22:47, , 7F
先用Microsoft.XMLHTTP,而不是XmlHttpRequest。
01/15 22:47, 7F

01/15 22:48, , 8F
看起來你是用ie7來做測試的。
01/15 22:48, 8F

01/15 23:05, , 9F
是用IE7...成功了,謝謝您
01/15 23:05, 9F
文章代碼(AID): #19RgQlKf (Ajax)
討論串 (同標題文章)
文章代碼(AID): #19RgQlKf (Ajax)