kxinzhu 2010-03-19 16:33
浏览 889
已采纳

<input type="button" value="check it" onclick="sendRequest();" /> 点击提示缺少对象

[color=red]点击后提示缺少对象什么原因[/color]<br> var XMLHttpReq;<br> var url=null;<br> var type=null;<br> //创建XMLHttpRequest对象<br><br> function createXMLHttpRequest() {<br> if(window.XMLHttpRequest) { //Mozilla 浏览器<br> XMLHttpReq = new XMLHttpRequest();<br> }<br> else if (window.ActiveXObject) { // IE浏览器<br> try {<br> XMLHttpReq = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);<br> } catch (e) {<br> try {<br> XMLHttpReq = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);<br> } catch (e) {}<br> }<br> }<br> }<br> //发送请求函数<br> function sendRequest() {</p> <pre><code> createXMLHttpRequest(); var url = &quot;/GetnameInfo&quot;; XMLHttpReq.open(&quot;GET&quot;, url, true); XMLHttpReq.onreadystatechange = getYg_name;//指定响应函数 XMLHttpReq.send(null); // 发送请求 } // 处理返回信息函数 function getYg_name() { if (XMLHttpReq.readyState == 4) { // 判断对象状态 if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息 var count = XMLHttpReq.responseXML.getElementsByTagName(&quot;count&quot;)[0].firstChild.nodeValue; for(var i=0;i&lt;count;i++) { var name = XMLHttpReq.responseXML.getElementsByTagName(&quot;name&quot;)[i].firstChild.nodeValue; var ygid=XMLHttpReq.responseXML.getElementsByTagName(&quot;ygid&quot;)[i].firstChild.nodeValue; var op = new Option(name[i].childNodes[i].nodeValue,ygid[i].childNodes[0].nodeValue); selectObj.options.add(op); } } } } else { //页面不正常 window.alert(&quot;您所请求的页面有异常。&quot;); } } } function nameinfo() { this.options[selectedIndex].text } &lt;/script&gt; &lt;body &gt; </code></pre> <table bgcolor="#F1E1FF" width="100%" height="5%"> <tr> <td> <center> <font size="12" color="RED">员工基本信息</font> </center> </td> </tr> </table> <form name="form1"> <table> <tr> <td bgcolor="#ACD6FF"> <font size="12">部门</font> </td> <td id='tdname'> <font size="6">姓 名</font> <select name="sbox" id="selectid" style="width: 150px" onchange="nameinfo()" /> <input type="text" id="tx1" value="" name="tx1" /> </td> </tr> <tr> <td id="td1"> <br> <input type="button" id="but1" value="开发部" onclick="sendRequest();" style="width: 120px; height: 30px; background-Color: #9cc5f8"> <br> <input type="button" id="but2" value="人事部" style="width: 120px; height: 30px; background-Color: #9cc5f8"> <br> <input type="button" id="but3" value="财务部" style="width: 120px; height: 30px; background-Color: #9cc5f8"> <br> <input type="button" id="but4" value="业务部" style="width: 120px; height: 30px; background-Color: #9cc5f8"> </td> <td></td> </tr> </table> </form> <p></body></p>

  • 写回答

4条回答

  • xxxxxxxxxxxxxxxxx 2010-03-19 17:08
    关注

    if else嵌套有问题。已修改。

    var XMLHttpReq; var url=null; var type=null; //创建XMLHttpRequest对象 function createXMLHttpRequest() { if(window.XMLHttpRequest) { //Mozilla 浏览器 XMLHttpReq = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE浏览器 try { XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } } //发送请求函数 function sendRequest() { createXMLHttpRequest(); var url = "/GetnameInfo"; XMLHttpReq.open("GET", url, true); XMLHttpReq.onreadystatechange = getYg_name;//指定响应函数 XMLHttpReq.send(null); // 发送请求 } // 处理返回信息函数 function getYg_name(){ if (XMLHttpReq.readyState == 4) { // 判断对象状态 if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息 var count = XMLHttpReq.responseXML.getElementsByTagName("count")[0].firstChild.nodeValue; for(var i=0;i<count;i++){ var name = XMLHttpReq.responseXML.getElementsByTagName("name")[i].firstChild.nodeValue; var ygid=XMLHttpReq.responseXML.getElementsByTagName("ygid")[i].firstChild.nodeValue; var op = new Option(name[i].childNodes[i].nodeValue,ygid[i].childNodes[0].nodeValue); selectObj.options.add(op); } } }else { //页面不正常 window.alert("您所请求的页面有异常。"); } } function nameinfo(){ this.options[selectedIndex].text = "some test"; }

    员工基本信息
    部门 姓 名




    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器