[英]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.