前端之家收集整理的这篇文章主要介绍了
使用ajax判断用户是否已经存在,并提示。,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用ajax判断用户是否已经存在,并提示。
<html>
<br/>
<script>
$(document).ready(
function()
{
$("#username").blur(function()
{
var q=$(this).val()
$.get('/checkuserexists/'+q,function(data,status)
{
//alert("val: "+q+ "Data: " + data + "\nStatus: " + status);
if(data!='0'){
//alert('user exists~~');
//alert($("#username").parent().html())
old=$("#username").parent().html();
//alert(old);
errormsg='<strong class="wrong">user exists</strong>';
$("#username").parent().html(old+errormsg)
}
}
)
//alert($(this).val());
});
}
)
</script>
<h1>Register</h1>
<form method="POST">
<table>
<tr><th><label for="username">username</label></th><td><input type="text" id="username" value="" name="usernam
e"/></td></tr>
<tr><th><label for="email">E-Mail</label></th><td><input type="text" id="email" value="11" name="email"/><stro
ng class="wrong">must be a valid email address</strong></td></tr>
<tr><th><label for="password">Password</label></th><td><input type="password" id="password" value="" name="pas
sword"/><strong class="wrong">must be between 3 and 20 characters</strong></td></tr>
<tr><th><label for="password2">Repeat password</label></th><td><input type="password" id="password2" value=""
name="password2"/></td></tr>
<tr><th><label for="submit"></label></th><td><button type="submit" id="submit" value="submit" name="submit">su
bmit</button></td></tr>
</table>
</form>
<a href='/listusers'>view all users</a>
</body>
</html>
原文链接:https://www.f2er.com/ajax/166763.html