看板 PHP 關於我們 聯絡資訊
<html> <head> <meta http-equiv="content-type" content = "text/html;charset=utf-8"> <script src = "utility.js" type = "text/javascript"></script> <script type = "text/javascript"> var XHR = null; function startRequest() { XHR = createXMLHttpRequest(); XHR.open("GET","poetry.txt",true); XHR.onreadystatechange=handleStateChange; XHR.send(null); } function handleStateChange() { if(XHR.readyState == 4) { if(XHR.status == 200) document.getElementByid("span1").innerHTML=XHR.responseText; else window.alert("error!"); } } </script> </head> <body> <form id = "form1"> <input id = "button1" type = "button" value = "顯示" onclick="startRequest()"> <br><br><span id = "span1"></span> </form> </body> </html> 基本上是照參考書上打的,但是button按了就一直顯示不出來 看了半天也不知道哪裡出錯,poetry.txt也建立了裡面也有內容 希望各位大大給新手一點幫助 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.135.159.117 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1484881760.A.70B.html
anest: 試試看在伺服器環境下跑網頁 01/20 11:27
mimikillua: else前後有括弧嗎? 01/20 11:37
wotupset: http://tinyurl.com/zq9zclf 01/20 13:46
感謝大家幫忙,不過更改過後還是無法顯示我在poetry.txt中的文字 請問還有哪裡出問題呢? 更改過後的程式碼如下 https://goo.gl/B9unxk ※ 編輯: biggood20708 (220.135.159.117), 01/20/2017 18:13:22
wotupset: 我不知道你的utility.js內容是什麼 你可以試著對照兩個 01/20 19:34
wotupset: 程式碼看哪邊有差異導致無法顯示 01/20 19:34
wotupset: javascript跟php不一樣 可以去Ajax板問看看 01/20 19:40
補充utility.js內容 https://goo.gl/roQvA5X ※ 編輯: biggood20708 (220.135.159.117), 01/20/2017 20:47:37
u5431269: XHR.open(GET,url,true) url路徑可能出錯了 01/21 01:07