怎样取得xmlHttp.responseText的返回值
代码如下,response.write要么写入1,要么写入0,单独运行index.asp完全正常,但用xmlHttp.responseText取值的时候返回的是一大段ht...
代码如下,response.write要么写入1,要么写入0,单独运行index.asp完全正常,但用xmlHttp.responseText取值的时候返回的是一大段html代码,请同志们帮着解决一下。
index.html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">
var xmlHttp = false;
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e2)
{
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
{
xmlHttp = new XMLHttpRequest();
}
function callServer()
{
var u_name = document.getElementById("u_name").value;
if ((u_name == null)||(u_name == ""))
return;
var url = "../system/4/index.asp?name=" + escape(u_name);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}
function updatePage()
{
if (xmlHttp.readyState < 4)
{
test1.innerHTML="<span style='padding-left:20px;width:200px;background:url(http://localhost/images/reg/loading.gif) no-repeat;color:#333333;line-height:20px;'>检测中……</span>";
}
if (xmlHttp.readyState == 4)
{
alert(xmlHttp.responseText);//返回的是HTML代码,而不是想要的1或0
}
}
</script>
<title>无标题 2</title>
</head>
<body>
<form name="form1" action="" method="post">
用户名: <input type="text" name="u_name" id="u_name" onchange="callServer();" />
<span id="test1">是否能注册 </span>
<br />
密 码: <input type="password" />
<input type="submit" name="submit" value="注册" />
</form>
</body>
</html>
index.asp代码:
<!--#include file="../system/0/default.asp"--> ‘数据库连接
<%
tKeyword=request("name")
mySQL="SELECT * From userInfo WHERE uNickName ='" & tKeyword &"'"
set myRs=myConn.Execute(mySQL)
If Not myRs.EOF Then
sFlag="0" '查询已存在
Else
sFlag="1"
End If
set myConn=nothing
set myRs=nothing
response.write sFlag
Response.End()
%> 展开
index.html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">
var xmlHttp = false;
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e2)
{
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
{
xmlHttp = new XMLHttpRequest();
}
function callServer()
{
var u_name = document.getElementById("u_name").value;
if ((u_name == null)||(u_name == ""))
return;
var url = "../system/4/index.asp?name=" + escape(u_name);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}
function updatePage()
{
if (xmlHttp.readyState < 4)
{
test1.innerHTML="<span style='padding-left:20px;width:200px;background:url(http://localhost/images/reg/loading.gif) no-repeat;color:#333333;line-height:20px;'>检测中……</span>";
}
if (xmlHttp.readyState == 4)
{
alert(xmlHttp.responseText);//返回的是HTML代码,而不是想要的1或0
}
}
</script>
<title>无标题 2</title>
</head>
<body>
<form name="form1" action="" method="post">
用户名: <input type="text" name="u_name" id="u_name" onchange="callServer();" />
<span id="test1">是否能注册 </span>
<br />
密 码: <input type="password" />
<input type="submit" name="submit" value="注册" />
</form>
</body>
</html>
index.asp代码:
<!--#include file="../system/0/default.asp"--> ‘数据库连接
<%
tKeyword=request("name")
mySQL="SELECT * From userInfo WHERE uNickName ='" & tKeyword &"'"
set myRs=myConn.Execute(mySQL)
If Not myRs.EOF Then
sFlag="0" '查询已存在
Else
sFlag="1"
End If
set myConn=nothing
set myRs=nothing
response.write sFlag
Response.End()
%> 展开
展开全部
var myXmlHttp=createXMLHTTP();
function createXMLDom()
{
var ActiveX = new Array("MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XMLDOM","MSXML.DOMDocument");
for(var i=0;i<ActiveX.length;i++)
{
try
{
return new ActiveXObject(ActiveX[i]);
}
catch(e)
{
return document.implementation.createDocument("", "", null);
}
}
return null;
}
///////////通用Ajax查询代码段,采用异步请求方式///////////////
//key为检测的数据内容;path为路径;str1为表名;str2为列名;iFlag为标志变量,决定调用哪个函数;
function ajaxQuery(key,path,str1,str2,iFlag)
{
var domPost;
domPost="<root><word>"+key+"</word><name>"+str1+"</name><list>"+str2+"</list></root>";
myXmlHttp.open("POST","../system/"+path+"/default.asp",true);
myXmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
//根据iFlag标志变量的值,
switch(iFlag)
{
//检查reg/用户名是否存在
case 0:
myXmlHttp.onreadystatechange=afterChkUser;
break;
}
myXmlHttp.send(domPost);
//tResult=myXmlHttp.responseText;
//return analysisXmlDom(tResult,"result");
}
function afterChkUser()
{
if(myXmlHttp.readyState<4)
{
document.getElementById("nameTips").className="msgLoading"; ///////////显示装入图片//////////
document.getElementById("nameTips").innerHTML=msgInfo[5];
}
if(myXmlHttp.readyState==4)
{
var tResult=myXmlHttp.responseText;
tResult= analysisXmlDom(tResult,"result");
if(tResult=="0") /////已经存在
{
var tUserID=document.getElementById("tUserName").value.replace(/(^[\s]*)|([/s]*$)/g,"");
document.getElementById("nameTips").className="msgErrorL";
document.getElementById("nameTips").innerHTML=msgInfo[2]+ "<a href='../login/?t="+tUserID+ "'> 登录</a>";
document.getElementById("tUserName").style.borderColor=colError;
bolFlag[0]=1;
}
else
{
document.getElementById("nameTips").className="msgRight";
document.getElementById("nameTips").innerHTML="";
document.getElementById("msgExtend").style.display="none";
document.getElementById("tUserName").style.borderColor=colFocus;
bolFlag[0]=2;
}
}
}
function analysisXmlDom(domString,domKey)
{
var myDom,rValue;
myDom=createXMLDom();
if(window.ActiveXObject)
{
myDom.loadXML(domString);
rValue=myDom.selectSingleNode("//"+domKey).text;
}
else
{
var myParser=new DOMParser();
myDom=myParser.parseFromString(domString,"text/xml");
rValue=myDom.documentElement.childNodes[0].firstChild.nodeValue;
}
return rValue;
}
function createXMLHTTP()
{
var xmlHTTP=null;
try
{
xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{//Firefox,Opera,Safari
xmlHTTP=new XMLHttpRequest();
}
return xmlHTTP;
}
后台:
<%
ON ERROR RESUME NEXT
dim myDomBack '声明传回前台的DOM
dim myDom,sFlag
SET myDomBack=CreateObject("MSXML2.DOMDOCUMENT")
SET myDom=CreateObject("MSXML2.DOMDOCUMENT")
myDOM.Load Request
myDOMBack.loadxml "<root><result></result></root>"
'查询数据库
dim tKeyword,tSheet,tHeader
tKeyword=myDOM.selectSingleNode("//word").text
tSheet=myDOM.selectSingleNode("//name").text
tHeader=myDOM.selectSingleNode("//list").text
If Err.Number<>0 then
Response.Redirect "http://localhost/"
Response.End
End if
mySQL="SELECT " & tHeader & " From " & tSheet & " WHERE " & tHeader & "='" & tKeyword &"'"
set myRs=myConn.Execute(mySQL)
If Not myRs.EOF Then
sFlag="0" '查询已存在
Else
sFlag="1"
End If
myDOMBack.selectSingleNode("//result").text=sFlag
myDOMBack.save Response
SET myRs=Nothing
SET myConn=Nothing
SET myDomBack=Nothing
SET myDom=Nothing
%>
function createXMLDom()
{
var ActiveX = new Array("MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XMLDOM","MSXML.DOMDocument");
for(var i=0;i<ActiveX.length;i++)
{
try
{
return new ActiveXObject(ActiveX[i]);
}
catch(e)
{
return document.implementation.createDocument("", "", null);
}
}
return null;
}
///////////通用Ajax查询代码段,采用异步请求方式///////////////
//key为检测的数据内容;path为路径;str1为表名;str2为列名;iFlag为标志变量,决定调用哪个函数;
function ajaxQuery(key,path,str1,str2,iFlag)
{
var domPost;
domPost="<root><word>"+key+"</word><name>"+str1+"</name><list>"+str2+"</list></root>";
myXmlHttp.open("POST","../system/"+path+"/default.asp",true);
myXmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
//根据iFlag标志变量的值,
switch(iFlag)
{
//检查reg/用户名是否存在
case 0:
myXmlHttp.onreadystatechange=afterChkUser;
break;
}
myXmlHttp.send(domPost);
//tResult=myXmlHttp.responseText;
//return analysisXmlDom(tResult,"result");
}
function afterChkUser()
{
if(myXmlHttp.readyState<4)
{
document.getElementById("nameTips").className="msgLoading"; ///////////显示装入图片//////////
document.getElementById("nameTips").innerHTML=msgInfo[5];
}
if(myXmlHttp.readyState==4)
{
var tResult=myXmlHttp.responseText;
tResult= analysisXmlDom(tResult,"result");
if(tResult=="0") /////已经存在
{
var tUserID=document.getElementById("tUserName").value.replace(/(^[\s]*)|([/s]*$)/g,"");
document.getElementById("nameTips").className="msgErrorL";
document.getElementById("nameTips").innerHTML=msgInfo[2]+ "<a href='../login/?t="+tUserID+ "'> 登录</a>";
document.getElementById("tUserName").style.borderColor=colError;
bolFlag[0]=1;
}
else
{
document.getElementById("nameTips").className="msgRight";
document.getElementById("nameTips").innerHTML="";
document.getElementById("msgExtend").style.display="none";
document.getElementById("tUserName").style.borderColor=colFocus;
bolFlag[0]=2;
}
}
}
function analysisXmlDom(domString,domKey)
{
var myDom,rValue;
myDom=createXMLDom();
if(window.ActiveXObject)
{
myDom.loadXML(domString);
rValue=myDom.selectSingleNode("//"+domKey).text;
}
else
{
var myParser=new DOMParser();
myDom=myParser.parseFromString(domString,"text/xml");
rValue=myDom.documentElement.childNodes[0].firstChild.nodeValue;
}
return rValue;
}
function createXMLHTTP()
{
var xmlHTTP=null;
try
{
xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{//Firefox,Opera,Safari
xmlHTTP=new XMLHttpRequest();
}
return xmlHTTP;
}
后台:
<%
ON ERROR RESUME NEXT
dim myDomBack '声明传回前台的DOM
dim myDom,sFlag
SET myDomBack=CreateObject("MSXML2.DOMDOCUMENT")
SET myDom=CreateObject("MSXML2.DOMDOCUMENT")
myDOM.Load Request
myDOMBack.loadxml "<root><result></result></root>"
'查询数据库
dim tKeyword,tSheet,tHeader
tKeyword=myDOM.selectSingleNode("//word").text
tSheet=myDOM.selectSingleNode("//name").text
tHeader=myDOM.selectSingleNode("//list").text
If Err.Number<>0 then
Response.Redirect "http://localhost/"
Response.End
End if
mySQL="SELECT " & tHeader & " From " & tSheet & " WHERE " & tHeader & "='" & tKeyword &"'"
set myRs=myConn.Execute(mySQL)
If Not myRs.EOF Then
sFlag="0" '查询已存在
Else
sFlag="1"
End If
myDOMBack.selectSingleNode("//result").text=sFlag
myDOMBack.save Response
SET myRs=Nothing
SET myConn=Nothing
SET myDomBack=Nothing
SET myDom=Nothing
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询