繁体   English   中英

JQuery.Validate()-远程规则

[英]JQuery.Validate() - remote rule

我正在为一个学校项目开发一个网站。 尽管我主要使用PHP,但我还是应该做一些客户端验证。 在Google中进行了很短的搜索,以找到Validate JQuery插件。 到目前为止,这是我所拥有的:

<form id="regform" class="well" method="post" action="Registering.php">
        <label>Name: <input type="text" placeholder="Type your name" name="Name" class="required" /></label>
        <label>Surname: <input type="text" placeholder="Type your surname" name="Surname" class="required" /></label>
        <label>Username: <input type="text" placeholder="Type your username" name="Username" class="required" /></label>
        <label>Password: <input type="password" placeholder="Type your password" name="Password" class="required" /></label>
        <label>Repeat Password: <input type="password" placeholder="Confirm Password" name="Password-confirm" class="required" /></label>
        <label>E-Mail: <input type="Email" placeholder="Type your Email" name="Email" class="required email" /></label>
        <label>Birthday: <input type="Date" name="Birthday" /></label>
        <label>Gender:</label>
        <label>Male <input type="radio" name="Gender" value="0" checked> Female <input type="radio" name="Gender" value="1"></label>
        <label>Photo: <input type="url" placeholder="Paste an image link" name="PhotoLink" class="url" /></label>
        <label><input type="submit" class="btn btn-primary" name="Submit" value="Register in YouTune" /></label>
 </form>

这是表格,几乎是标准注册表格。 没什么可添加的。 然后我有这个小的Javascript:

$(document).ready(function(){
        $("#regform").validate({
            rules: {
                Username: {
                    remote: { url: "/check_username.php", async: false }
                }
            },
            messages: {
                Username: { remote: "Username already on use. Pick a different one." }
            }
        });
});

最新的JQuery库脚本和版本1.10的Validate Plugin均添加在文档的开头。

好了,简而言之,除了远程规则不起作用之外,验证工作运行顺利。 好像根本就没有,无论我是否使用已经使用过的用户名提交,都不会出现错误消息。 Javascript正在调用的php文件具有以下脚本:

<?php error_reporting(E_ALL);
     require_once("../Clases/User.php");
     header('Content-type: application/json');
     $vUser = new User();
     $vResult = $vUser->GetUserByUsername($_REQUEST["Username"]);
     if ($vResult) {
    echo false;
     } else { echo true; }

?>

GetUserByUsername方法转到数据库并搜索具有给定参数的User,然后如果匹配成功,则返回true,否则返回false。 我已经对它进行了测试,而没有从Javascript进行远程调用,它工作正常

那么,有谁知道为什么会这样?

预先感谢您抽出宝贵的时间阅读并尝试帮助我解决这个小问题。

编辑:解决。 我只需要修复远程呼叫的来源。 不敢相信我错过了。 无论如何,非常感谢您的帮助。

我不太确定,但是看看是否可行。 从您的网址中删除“ /”。 使用“ check_username.php”代替“ /check_username.php”或绝对网址

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM