远程时jQuery验证插件停止
Posted
技术标签:
【中文标题】远程时jQuery验证插件停止【英文标题】:jquery validation plugin stops when remote 【发布时间】:2014-03-05 05:35:57 【问题描述】:这表明我的一个项目有一个小问题。
我在这个表单上使用 jquery 验证插件:
<input type="text" name = "lname" placeholder="Last Name" id="lname" required/> <label for="lname" generated="true" class="error"></label> <input type="text" name = "email" placeholder="E-mail" id="email" class="email" required/> <label for="email" generated="true" class="error"></label> <input type="text" name = "username" placeholder="Username" id="username" required/> <label for="username" generated="true" class="error"></label> <input type="password" name = "password" placeholder="Password" id="password" required/> <label for="password" generated="true" class="error"></label> <input type="password" name = "cpassword" placeholder="Confirm Password" id="confirm_password" required/> <label for="cpassword" generated="true" class="error"></label> <input class="button" type="submit" name="regbutton" id="regbutton" value="Register" /> </form>
以下是规则:
$(document).ready(function ()
$('#registration').validate(
rules: fname: minlength: 3, , lname: minlength: 3, , email: email: true, remote: url:"../php/checkemail.php", async:false > , username: minlength: 4, maxlength: 16, remote: url:"../php/checkusername.php", async:false , password: minlength: 8, maxlength: 16, , cpassword: equalTo: "#password", , , messages: fname: minlength: "Your name must be at least 3 characters long.", , lname: minlength: "Your name must be at least 3 characters long.", , email: email: "Please enter a valid e-mail address.", remote: "This email is already registered.", , username: minlength: "Your username must be at least 4 characters long but less than 16", maxlength: "Your username must be at least 4 characters long but less than 16", remote: "This username is already registered.", , password: minlength: "Your password must be at least 8 characters long but less than 16", maxlength: "Your password must be at least 8 characters long but less than 16", , cpassword: equalTo: "The passwords do not match.", , , submitHandler: function(form) $('#registration').submit(); return false; ,
); );
还有 checkemail.php(checkusername.php 是一样的,但显然是用用户名而不是电子邮件):
包括('dbcon.php'); if (isset($_POST['email']))
$email = mysql_real_escape_string($_POST['email']); if (!empty($email)) $email_query = mysql_query("SELECT * FROM users WHERE email = '$email'"); if($email_query) echo "true"; exit; else echo "false"; exit;
我已经尝试了我找到的所有组合。简单的遥控器:“url”,具有类型和数据的那个:function....等。没有任何接缝可以工作......检查PHP文件也是如此,每当我将远程线放在我的验证中时当我点击提交时,代码表单停止工作。如果我删除远程线路一切正常。有谁知道可能是什么问题?我真的没有想法,也无处可寻。
【问题讨论】:
【参考方案1】:所以,
我将我的 php 文件更改为这个,因为我认为这是我的整个验证停止的地方:
if(isset($_POST['email']))
$email = mysqli_real_escape_string(strtolower($_POST['email']));
$check= mysqli_query("SELECT * FROM users WHERE LOWER email = '$email'");
if(mysqli_stmt_num_rows($check))
echo "false";
其他
echo "true";
但仍然没有...我没有收到任何消息,我的表单没有提交,除非我删除“remote:”url“”部分......然后一切都很好......
【讨论】:
【参考方案2】:我让那部分工作,问题接缝是相对 url,它找不到 php 文件,所以我现在使用 ./ 而不是 ../ 并且它一直工作到那里,但在控制台中它给了我 200 ok 并且无论电子邮件和用户是否可用,它都会向我发送“真实”,并且它没有在表单中给我任何消息......有没有人知道如何解决这个问题?
另外,如果我输入 data: x: function.... 并键入它会跳过整个验证,让我提交一个空表单。
【讨论】:
以上是关于远程时jQuery验证插件停止的主要内容,如果未能解决你的问题,请参考以下文章