初学ajax, alert(xmlHttp.status)却显示为0

来源:百度知道 编辑:UC知道 时间:2024/05/20 04:43:44
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html xmlns="http://www.w3.org/1999/xhmlt">
<head>
<title>simple request</title>
<script type="text/javascript">
var xmlHttp
function createXMLHttpRequest()
{
if(window.ActiveXObject)
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
else if(window.XMLHttpRequest)
xmlHttp=new XMLHttpRequest();

}
function startRequest()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("GET","simpleResponse.xml",true);
xmlHttp.send(null);
}
function handleStateChange()
{
if(xmlHttp.readystate==4)
{
alert(xmlHttp.

貌似url问题,你请求的是一个xml?,我没试过这样玩。我一般都请求jsp,然后response一个xml回来

xml的玩法应该是这种
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async= false;
xmlDoc.load("xml/books.xml");

遇到同样的问题啊!!求解决方案!!有人回答了,麻烦楼主分享一下。。。