ASP中AJAX连接Access数据库后出错原因不明

hwg05 2012-07-29 06:57:04
用户名检测页面index.asp运行正常。服务器页面Server.asp单独运行也正常,可是用AJAX把两个连起来后运行就出现错误,不知是何原因,请高手指教。

'index.asp用户名检测页面
<html>
<head>
<title>用户名检测</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript">
/* var httpRequest;
//创建XMLHttpRequest对象
function createXMLHttpRequest() {
/* if(window.ActiveXObject)
httpRequest = new ActiveXObject("MSXML2.XMLHTTP.6.0");
else if(window.XmlHttpRequest)
httpRequest = new XmlHttpRequest();
else
try{
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");}
catch
{
alert("对不起,浏览器不支持该对象 xmlhttprequest");
}
}*/
var httpRequest;
//创建XMLHttpRequest对象
function createXMLHttpRequest() {
if(window.XMLHttpRequest) { //非IE浏览器
httpRequest = new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IE浏览器
httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
}
//发送请求函数
function sendRequest(url) {
createXMLHttpRequest();
httpRequest.open("GET",url,true);
httpRequest.onreadystatechange = processResponse;//指定响应函数
httpRequest.send(null); // 发送请求
}
// 处理返回信息函数
function processResponse() {
if (httpRequest.readyState == 4) { // 判断对象状态
if (httpRequest.status == 200) { // 信息已经成功返回,开始处理信息
var obj=document.getElementById("res");
var Result=httpRequest.responseText;
obj.innerHTML=Result;
//window.alert("数据返回成功!");
window.alert(obj.innerHTML);
} else { //页面不正常
window.alert("请求页面异常");
}
}
}
// 用户名验证函数
function userCheck() {
var username = document.getElementById("mobile").value;
if(userName =="") {
window.alert("用户名不能为空");
document.myform.mobile.focus();
return false;
}
else {
var url="Login.asp?userName="+ userName;
sendRequest(url);
}
}
</script>

</head>
<body>
<form name=form1 id="myform" method=post action="Login.asp?yanzi()" onsubmit="checkPhone(mobile.value);" >
用户名:<input type="text" name="mobile" id="mobile">
<input type=Button name= "MemberButton " value= "提交" onClick= "userCheck();" id="Button" /><br>
<div id="res"></div>
</form>
</body>
</html>


'服务器页面server.asp
<!--#include file="sub/conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>

</head>
<body>
<%

'Response.ContentType = "text/html"
'Response.Charset = "utf-8"
dim username,sql
username=request.querystring("username")
username="999"
set rs=server.createobject("adodb.recordset")
sql="select id username from love_main where username='"&username&"'"
rs.open sql,conn,1,3
if rs.bof or rs.eof then
response.write ("恭喜您!用户名可以使用。")
else
response.write ("用户名已被占用,请用别的名称")
end if
rs.close
set rs=nothing
%>

</body>
</html>
...全文
123 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
格桑花 2012-07-30
  • 打赏
  • 举报
回复
hwg05 2012-07-30
  • 打赏
  • 举报
回复
俺还是自己找到原因了。是因为所连接的Aceess数据库后缀名改为ASP后,AJAX无法调用,把后缀名改为mdb后调用一切正常了。
hwg05 2012-07-29
  • 打赏
  • 举报
回复
按二楼的说明也不行,代码上己经用逗号隐藏了。
补充说明一下:
服务器页面server.asp在非数据库连接的情况下,能够返回值到index.asp页面,但一连接数据库就出错。原以为是不是浏览器不兼容,使用index.asp页面上隐藏的浏览器判断代码也是出错。而server.asp页面在使用非数据库连接的下面的代码时运行正常:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
dim mobile,msg
mobile= Trim(Request.QueryString("userName"))
Randomize
msg = Int(89999*Rnd)+10000
sendsms trim(replace(request("mobile"),",",",")),trim(request("msg"))
Response.Write(msg)
%>
</body>
</html>
请各位高手看看问题是出在哪里?
licip 2012-07-29
  • 打赏
  • 举报
回复
'Response.ContentType = "text/html"
这个地方是不是应该为:
'Response.ContentType = "text/plain"

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧