<script type="text/javascript"> var pathName = document.location.pathname; var index = pathName.substr(1).indexOf("/"); var app = pathName.substr(0, index + 1); var xmlhttp; function load(url, func) { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = func; xmlhttp.open("GET", url, true); xmlhttp.send(); } function check(number) { load(app + "/checknumber?guessnumber=" + number, function () { if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { checkingdiv = document.getElementById("checking"); checkingcontent = xmlhttp.responseText; if (checkingcontent.trim().length === 0) { checkingdiv.removeAttribute("style"); } else { checkingdiv.setAttribute("style", "border: 1px dashed blue;"); } checkingdiv.innerHTML = checkingcontent; } }); } </script>调用部分: <table> <tr> <td> <input type="text" name="number" /></td> <td><input type="submit" value="猜" onclick="check(<%=request.getParameter("number")%>)"/></td> <td><div id="checking"></div></td> </tr> </table>
1 回答
风筝_0010
TA贡献45条经验 获得超15个赞
这句有明显的问题啊。。。。
load(app + "/checknumber?guessnumber=" + number, function () { if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { checkingdiv = document.getElementById("checking"); checkingcontent = xmlhttp.responseText; if (checkingcontent.trim().length === 0) { checkingdiv.removeAttribute("style"); } else { checkingdiv.setAttribute("style", "border: 1px dashed blue;"); } checkingdiv.innerHTML = checkingcontent; } }
你这个回调函数里面xmlhttp是哪里来的?我知道你是new的XHR对象,但是你传参数的时候这个回调函数不知道啊,肯定会报错吧。。。用this代替里面的xmlhttp
添加回答
举报
0/150
提交
取消