[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("Msxml2.XMLHTTP");<br> } catch (e) {<br> try {<br> XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");<br> } catch (e) {}<br> }<br> }<br> }<br> //发送请求函数<br> function sendRequest() {</p> <pre><code> 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 } </script> <body > </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>
<input type="button" value="check it" onclick="sendRequest();" /> 点击提示缺少对象
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
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"; }员工基本信息 部门 姓 名
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥60 版本过低apk如何修改可以兼容新的安卓系统
- ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!
- ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?