douyun8674 2012-10-08 23:54
浏览 53

JQuery.Validate() - 远程规则

I'm developing a Web site for a school project. Though I mainly work with PHP, I thoght I should as well do some client-side validation. It took a very short search in Google to find the Validate JQuery plugin. And so far this is what I've got:

<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>

This is the form, pretty much a standard registration one. Nothing to add here. And then I have this small 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." }
            }
        });
});

Both scripts of the lastest JQuery library and the version 1.10 of the Validate Plugin were added on the head of the document.

Well, to make it short, the validation stuff runs smooth, except that the remote rule is not working. It is as if it wasn't there at all, no error message whether I submit with an already used Username or not. The php file that the Javascript is calling has the following script:

<?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; }

?>

The GetUserByUsername method goes to a DataBase and searches for a User with the given parameter, then returns true if there was a match up, false if there wasn't. I've tested it without the remote call from the Javascript and it works fine

So, does anyone know why is this happening?

Thank you beforehand for taking the time read and trying to help me with this small issue.

EDIT: Solved. I just had to fix the source for the remote call. Can't believe I missed that. Anyway, thank you very much for the help.

  • 写回答

1条回答 默认 最新

  • doushi2047 2012-10-09 14:02
    关注

    I am not very sure but see if it works; remove "/" from your url. use "check_username.php" in place of "/check_username.php" or absolute url

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100