[请益] 新手http response无法显示求解

楼主: biggood20708 (Neoli)   2017-01-20 11:09:17
<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也建立了里面也有内容
希望各位大大给新手一点帮助
作者: anest (形状最重要大小不能少)   2017-01-20 11:27:00
试试看在服务器环境下跑网页
作者: mimikillua   2017-01-20 11:37:00
else前后有括号吗?
作者: wotupset (wotupset)   2017-01-20 13:46:00
http://tinyurl.com/zq9zclf我不知道你的utility.js内容是什么 你可以试着对照两个程式码看哪边有差异导致无法显示javascript跟php不一样 可以去Ajax板问看看
作者: u5431269 (GIGGS)   2017-01-21 01:07:00
XHR.open(GET,url,true) url路径可能出错了

Links booklink

Contact Us: admin [ a t ] ucptt.com