且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery验证程序表单:完成远程电子邮件验证后,如何访问表单操作

更新时间:2022-12-07 10:36:02

您的服务器端代码应更像这样...

Your server-side code should look more like this...

if (!$userHandler->isEmailAvailable($email)) {
    // failed validation
    echo json_encode("Email Address is already registered: " . $email); 
} else {
    // passed validation
    echo "true"; 
}
exit;

如果返回true,结果将变为错误消息1.

If a true is returned the result becomes the error message, 1.

这是因为true是布尔值(1),并且插件需要一个字符串.从字面上看,不是"true"(字符串)的任何 都将被视为验证失败,并且会显示一条错误消息:

That is because the true is a boolean (1), and the plugin is expecting a string. Literally, anything that is not a "true" (string), is considered failed validation and will give you an error message:

  • 如果响应为"false"undefinednull,则您会收到一般错误消息.

  • If the response is "false", undefined, or null, then you get the generic error message.

如果响应为"true",则表明您已通过验证并且未显示任何消息.

If the response is "true", then you've passed validation and no message is displayed.

如果响应为其他响应,则该响应将成为错误消息字符串.

If the response is anything else, that response becomes the error message string.