ajax应用中的Internal Server Error问题?

liusylon 2006-04-10 06:29:45
学习的一个例子,注册时检测用户名存在并提示

<!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>
<title>注册</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="script/ajax.js"></script>
<script type="text/javascript">
//获取页面指定ID公用函数
function GE(a){return document.getElementById(a);}
//表单检测
function Check(){
//检测ID是否为空
if(GE('regid').value==''){GE('msg').innerHTML='ID不能为空';return false}
//检测PASSWORD是否为空
//if(GE('regpassword').value==''){GE('msg').innerHTML='password 不能为空';return false}
//检测OK后提交数据

//建立XMLHttpRequest对象
var X=new XMLHttpRequest();
//检测浏览器是否支持XMLHttpRequest
if(X){
//禁止客户端再次提交表单
GE('regsubmit').disabled=true;
//onreadystatechange为XMLHttpRequest的状态改变的事件触发器
X.onreadystatechange=function(){

//readyState 对象状态
//0 = 未初始化
//1 = 读取中
//2 = 已读取
//3 = 交互中
//4 = 完成
if(X.readyState==4){
//交互完成的处理
//status,服务器返回的状态码, 200为成功
if(X.status==200){
//运行服务器返回的脚本
eval(X.responseText);
}
//服务器端程序运行失败,返回错误代码
else{GE('msg').innerHTML=X.statusText}
}
};
//获取服务器端数据
//open("method","URL"[,asyncFlag])
//请求的目标 URL, 方法
//采用POST为提交数据
//采用true为异步传输, false为同步传输

X.open('POST','reg_teacher.asp',true);
X.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
var SendData = 'StudentName='+GE('regid').value;
X.send(SendData);
}
//不支持的话返回错误提示
else{
GE('msg').innerHTML='你的浏览器不支持XMLHttpRequest'
}
}
</script>
</head>
<body>
<div id="msg"></div>
ID: <input type="text" id="regid" onchange="Check()" /><br />
Password: <input type="password" id="regpassword" /><br />
<input type="submit" id="regsubmit" />
</body>
</html>

服务端代码:

<%
if request("StudentName")<>"" then
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from Students where StudentName='"&request("StudentName")&"'",conn,1,1
if rs.recordcount>0 then
str="该用户名已存在了!"
else
    ..... ..... .....
     end if

Response.Write "GE('msg').innerHTML='" & str & "';GE('regsubmit').disabled=false"
Response.End
%>
end if
end if
%>
<!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=gb2312" />
<title>无标题文档</title>
</head>

<body>
</body>
</html>

结果出现Internal Server Error的错误?
...全文
3190 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SlamAI 2006-04-10
  • 打赏
  • 举报
回复
。。。
偶也正在问编码的问题
不过你的应该好说一些

用XMLHTTP组件在读页面的时候,读出来的数据默认为UTF-8编码
你只需要把你服务器端以UTF-8编码格式输出内容即可

在ASP页面顶部添加
<%@ CodePage=65001 Language="VBScript"%>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
改为
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
liusylon 2006-04-10
  • 打赏
  • 举报
回复
%>
end if
end if
%>
多个东西,呵呵,不过显示回来的乱码,怎么解决这个中文显示的问题呢?
应该显示的是这个
"该用户名已存在了!"
孟子E章 2006-04-10
  • 打赏
  • 举报
回复
end if
end if
??多了一个
孟子E章 2006-04-10
  • 打赏
  • 举报
回复
Internal Server Error说明你请求的页面的代码有问题,如变量未定义,数据库理解出错等

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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