文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学的各位小编整理了Ajax-AJAX应用之注册用户即时检测的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
AJAX的无刷新机制使得在注册系统中对于注册名称的检测能即时显示。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); } |
<!--cu.asp的源码示例--> <!--#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 %> |
function updatePage() { if (xmlHttp.readyState < 4) { test1.innerHTML="loading..."; } if (xmlHttp.readyState == 4) { var response = xmlHttp.responseText; test1.innerHTML=response; } } |