新手请教一个关于xmlHttp.status的问题
<P>代码如下:<BR>var xmlHttp;<BR>//创建XMLHttpRequest对象<BR>function createXMLHttpRequest(){<BR> if(window.ActiveXObject){<BR> xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");<BR> }<BR> else if( window.XMLHttpRequest ){<BR> xmlHttp = new XMLHttpRequest();<BR> }<BR>}</P><P>//发送请求<BR>function startRequest(){<BR> createXMLHttpRequest();<BR> xmlHttp.onreadystatechange = handleStateChange;<BR> xmlHttp.open("GET","simpleRequest.xml",true);<BR> xmlHttp.send(null);<BR>}<BR><BR>//处理响应<BR>function handleStateChange(){<BR> if( xmlHttp.readyState == 4 ){<BR> {<BR> if( xmlHttp.status == 200 ){<BR> alert("Server response with:"+xmlHttp.responseText);<BR> }<BR> }<BR> }<BR>}<BR>运行后无预期结果-------弹出提示窗口.而将处理响应函数改为如下后就可以:<BR>function handleStateChange(){<BR> if( xmlHttp.readyState == 4 ){<BR> {<BR> alert("Server response with:"+xmlHttp.responseText);<BR> }<BR> }<BR>}<BR>请教这是什么原因啊?</P> //发送请求<BR>function startRequest(){<BR> createXMLHttpRequest();<BR> <FONT color=#ff0000>xmlHttp.open("GET","simpleRequest.xml",true);<BR> xmlHttp.send(null);<BR> xmlHttp.onreadystatechange = handleStateChange;<BR></FONT>} <P>1.//发送请求<BR>2.function startRequest(){<BR>3. createXMLHttpRequest();<BR>4. xmlHttp.onreadystatechange = handleStateChange;<BR>5. xmlHttp.open("GET","simpleRequest.xml",true);<BR>6. xmlHttp.send(null);<BR>7.}<BR>rainic,感谢你的回复,把4,5,6行照你标出来的顺序互换吗?我试过了,没有什么反应,连窗口都不跳出了.<BR>能给我说说你的思路吗?<BR></P>
<P>怎么没有人给小弟解释下,斑竹呢?</P> 要先发送,。才会有onreadystatechange<BR><BR>当readyState == 4 , status == 200时,才能说明服务器返回的数据是正常的<BR><BR><BR>你去掉了status == 200这个条件,服务器返回不正常的数据时也会弹出提示框。没什么意义 我想问xmlhttprequest.status返回的错误码是500,不知道是什么原因?[em03] 返回 500 是sql语句的错误!!!仔细找找就可以了 <DIV class=quote><B>以下是引用<U>笨笨的编程小子</U>在2007-3-24 12:58:51的发言:</B><br>返回 500 是sql语句的错误!!!仔细找找就可以了</DIV>
<P>[em09]头一次见这种说法。。。。</P><br>楼上的老兄,建议你<a href="http://www.w3pop.com/tech/school/tags/ref_httpmessages.asp" target="_blank" ><FONT color=#0000ff>进去</FONT></A>看看
[align=right][color=#000066][此贴子已经被作者于2007-4-5 11:46:35编辑过][/color][/align]
页:
[1]
