ITeye博客

登录中使用ajax判断用户是否存在

makuixuan · 2010-12-30 15:42 · Ajax · Web前端 · Ajax · ASP · VBScript · Microsoft · JavaScript · Markdown

[code="html文件"] 无标题文档

用户名:
密 码:

[/code] [code="js文件"] // JavaScript Document 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 = "userCheck.asp?name=" + escape(u_name);//查询地址 返回值为"已被注册"或"可以注册" xmlHttp.open("GET", url, true); xmlHttp.onreadystatechange = updatePage; xmlHttp.send(null); } function updatePage() { if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200){ var response = xmlHttp.responseText; if (response == "true"){ test1.innerHTML=""; } else{ test1.innerHTML = "用户名不存在,请重新输入!"; document.getElementById("u_name").value=""; document.getElementById("u_name").focus(); } } else if(xmlHttp.status==500){ test1.innerHTML=xmlHttp.responseText; } } } [code="userCheck.asp文件"] <%@LANGUAGE="VBSCRIPT"%> <% username = request.querystring("name") if (username = "ajax") then response.write "true" else response.write "false" end if %> [/code] [/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。