如何判断录入的文本值在数据库中是否存在???? 想实现在文本框录入后就校验出值是否在数据库中的表中存在,不要等到提交的时候才判断,如何写,如果不行,怎么写能简单呢,要代码哦 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ajax把录入的文本传递到后台查数据库进行验证,如已存在则在页面上进行提示。 <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 = "cu.asp?name=" + escape(u_name); xmlHttp.open("GET", url, true); xmlHttp.onreadystatechange = updatePage; xmlHttp.send(null); }function updatePage() { if (xmlHttp.readyState < 4) { emailts.innerHTML="系统将自动检测您的用户名是否已被注册,请稍候..."; } if (xmlHttp.readyState == 4) { var response = xmlHttp.responseText; if (response=="true"){ emailts.innerHTML='恭喜你,用户名还未被注册!'; emailts.className="showok"; } else{ emailts.innerHTML='对不起,用户名已被注册!'; emailts.className="showno"; } }}</script><style type="text/css"><!--.showno { color: #FF0000; font-weight: bold; background:url("note_error.gif") no-repeat 12px center; padding-left:35px; }.showok { color: #FF0000; font-weight: bold; background:url("note_ok.gif") no-repeat 12px center; padding-left:35px; }--></style></head><body><table cellspacing="0" cellpadding="0" width="694" border="0"> <tbody> <tr> <td width="179" height="40" align="right" class="F14">用户名:</td> <td width="168"><input id="u_name" onChange="callServer();" style="WIDTH: 155px" /> </td> <td width="347"> <div id="emailts"></div></td> </tr> <tr> <td height="40" align="right" class="F14">Email地址:</td> <td colspan="2"><input id="email" style="WIDTH: 155px" /> </td> </tr> </tbody></table> cu.asp<%Response.Buffer = True Response.ExpiresAbsolute = Now() - 1 Response.Expires = 0 Response.CacheControl = "no-cache" Response.AddHeader "Pragma", "No-Cache"%><!--#include file="conn.asp"--><%name=request.querystring("name")Set rs = Server.CreateObject ("ADODB.Recordset")sql = "Select * from u_ser where u_name='"&name&"'"rs.Open sql,conn,1,1if rs.eof and rs.bof then response.write("true")else response.write("false")end ifrs.closeset rs=nothingcall CloseDatabase%> http://blog.csdn.net/ws_hgo/archive/2009/07/28/4388800.aspx JB9是javabulider9?这跟语言没关系,LZ研究一下AJAX的原理和实现就明白了。 到baidu, google去搜一下ajax学习就好了,建议用jquery,更加方便 寻求个demo Jquery获取焦点事件的问题 window.open窗口,OpenWindow.document.write如何调用js文件的语句? JS怎么实现这样的复选框 100分求有点难度的进度条效果 跪求做和算法a+b+c=d chrome 上奇怪的问题 谁对CSS滤镜的Light滤镜比较熟悉啊?请进来看看。198 javascript问题,非常简单!! 菜鸟碰到jQuery初级神坑问题,请高手来解释,感谢,有代码初门级很简单 紧急求助,ext.form.checkboxgroup 如何重新渲染 js主题皮肤更换
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 = "cu.asp?name=" + escape(u_name);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}function updatePage() {
if (xmlHttp.readyState < 4) {
emailts.innerHTML="系统将自动检测您的用户名是否已被注册,请稍候...";
}
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
if (response=="true"){
emailts.innerHTML='恭喜你,用户名还未被注册!';
emailts.className="showok";
}
else{
emailts.innerHTML='对不起,用户名已被注册!';
emailts.className="showno";
}
}
}
</script>
<style type="text/css">
<!--
.showno {
color: #FF0000;
font-weight: bold;
background:url("note_error.gif") no-repeat 12px center;
padding-left:35px;
}
.showok {
color: #FF0000;
font-weight: bold;
background:url("note_ok.gif") no-repeat 12px center;
padding-left:35px;
}
-->
</style>
</head><body>
<table cellspacing="0" cellpadding="0" width="694" border="0">
<tbody>
<tr>
<td width="179" height="40" align="right" class="F14">用户名:</td>
<td width="168"><input id="u_name" onChange="callServer();" style="WIDTH: 155px" />
</td>
<td width="347"> <div id="emailts"></div></td>
</tr>
<tr>
<td height="40" align="right" class="F14">Email地址:</td>
<td colspan="2"><input id="email" style="WIDTH: 155px" /> </td>
</tr>
</tbody>
</table> cu.asp<%
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "No-Cache"
%>
<!--#include file="conn.asp"-->
<%
name=request.querystring("name")
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from u_ser where u_name='"&name&"'"
rs.Open sql,conn,1,1
if rs.eof and rs.bof then
response.write("true")
else
response.write("false")
end if
rs.close
set rs=nothing
call CloseDatabase
%>