xmlHttp.status的返回值总是0
源码如下,声明下我初学的绝对是菜鸟,希望高手帮解决下varxmlHttp=createXmlHttpRequest();functioncreateXmlHttpRequ...
源码如下,声明下我初学的绝对是菜鸟,希望高手帮解决下
var xmlHttp=createXmlHttpRequest();
function createXmlHttpRequest()//创建XmlHttpRequest对象
{
var xmlHttp;
try
{
xmlHttp=new XmlHttpRequest()
}
catch (e)
{
var XmlHttpVersions=new Array('MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP');
for(var i=0;i<XmlHttpVersions.length&&!xmlHttp;i++)
{
xmlHttp=new ActiveXObject(XmlHttpVersions[i]);
}
if(!xmlHttp)
{
alert("Error creating the XMLHttpRequest object.");
}
else
{
return xmlHttp;
}
}
}
function addUser()
{
if(xmlHttp)
{
try
{
username=encodeURIComponent(document.getElementById("username").value);
password=encodeURIComponent(document.getElementById("password").value);
email=encodeURIComponent(document.getElementById("email").value);
//question=encodeURIComponent(document.getElementById("question").value);
//answer=encodeURIComponent(document.getElementById("answer").value);
username=encodeURIComponent(document.getElementById("username").value);
var urlStr="userReg.php?username="+username+"&password="+password+"&email="+email;
xmlHttp.open("GET",urlStr,true);
xmlHttp.onreadystatechange=handleRequestState;
xmlHttp.send(null);
}
catch (e)
{
alert("Can't connect to server:\n"+e.toString());
}
}
}
function handleRequestState()
{
if(xmlHttp.readystate==4)
{
if(xmlHttp.status==200)
{
document.write("all is ok");
}
else
{
//document.write("err23or");
//document.write(xmlHttp.getResponseHeader("Content-Type"));
document.write(xmlHttp.responseText);
document.write(xmlHttp.status.Text);
document.write(xmlHttp.status);
}
}
} 展开
var xmlHttp=createXmlHttpRequest();
function createXmlHttpRequest()//创建XmlHttpRequest对象
{
var xmlHttp;
try
{
xmlHttp=new XmlHttpRequest()
}
catch (e)
{
var XmlHttpVersions=new Array('MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP');
for(var i=0;i<XmlHttpVersions.length&&!xmlHttp;i++)
{
xmlHttp=new ActiveXObject(XmlHttpVersions[i]);
}
if(!xmlHttp)
{
alert("Error creating the XMLHttpRequest object.");
}
else
{
return xmlHttp;
}
}
}
function addUser()
{
if(xmlHttp)
{
try
{
username=encodeURIComponent(document.getElementById("username").value);
password=encodeURIComponent(document.getElementById("password").value);
email=encodeURIComponent(document.getElementById("email").value);
//question=encodeURIComponent(document.getElementById("question").value);
//answer=encodeURIComponent(document.getElementById("answer").value);
username=encodeURIComponent(document.getElementById("username").value);
var urlStr="userReg.php?username="+username+"&password="+password+"&email="+email;
xmlHttp.open("GET",urlStr,true);
xmlHttp.onreadystatechange=handleRequestState;
xmlHttp.send(null);
}
catch (e)
{
alert("Can't connect to server:\n"+e.toString());
}
}
}
function handleRequestState()
{
if(xmlHttp.readystate==4)
{
if(xmlHttp.status==200)
{
document.write("all is ok");
}
else
{
//document.write("err23or");
//document.write(xmlHttp.getResponseHeader("Content-Type"));
document.write(xmlHttp.responseText);
document.write(xmlHttp.status.Text);
document.write(xmlHttp.status);
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询