jQuery验证远程方法的使用情况,以检查用户名是否已经存在。
$("#signupForm").validate({ rules: { username: { required: true, minlength: 3, remote: "check-username.php" } }, messages: { username:{ remote: "This username is already taken! Try another." } } });
<?php require_once "./source/includes/data.php";header('Content-type: application/json'); $name = mysql_real_escape_string($_POST['username']); $check_for_username = mysql_query("SELECT username FROM mmh_user_info WHERE username='$name'"); if (mysql_num_rows($check_for_username) > 0) { $output = true;} else { $output = false;}echo json_encode($output);?>
冉冉说