使用远程方法在jQuery的验证问题 [英] Issue using remote method in jquery validation

查看:145
本文介绍了使用远程方法在jQuery的验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面这个的文章,以验证自己的状态

I'm following this article in order to validate my form

我的问题是,当我必须使用远程的方法,如远程:签username.php

My problem is when I have to use the remote method, e.g. remote: "check-username.php"

由于远程方法的文档不是那么清楚,我,我会知道:

Since the documentation for remote method is not so clear for me, I would know:

我需要怎么构建我的JSON输出在PHP脚本?

How I need to structure my json output in php script?

推荐答案

您不需要JSON。你可以把任何文本。例如,您可以

You don't need JSON. You can put any text. For example you can

echo "success";

有关通过验证,并输入验证信息,如:

for passed validation, and enter validation message like:

echo "Username already exists.";

对于未通过验证。

for failed validation.

在你的回调做这样的事情:

In your callback do something like this:

remote: {
           url: "check-username.php" ,
           type: "post" ,
           data: {
              username: function() {
                 return $("#username").val();
           },
           complete: function(data){
                      if( data.responseText != "success" ) {
                        alert(data.responseText);
                        //handle failed validation
                       }
             }
         }

这篇关于使用远程方法在jQuery的验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆