Weird, the 'validate' didn't show in my subject, maybe it will now.

Well, I figured out a solution, and it works pretty well :D

        var email_ajax_data;
        $.validator.addClassRules({
                email: {
                        required: true,
                        email: true,
                        remote: {
                                url: "/ajax/check_email",
                                type: "post",
                                dataFilter: function(data) { email_ajax_data = 
data; return
data; },
                                complete: function() {
                                        status = eval( '('+email_ajax_data+')' 
);
                                        if (status == 'false' || !status) { 
//if false show msg
                                                $('#email_notice').show();

                                        } else {
                                                $('#email_notice').hide();
                                        }
                                }
                        }
                }
        });


In this example I don't use it for much, but I'm also using it in a
number of other sections where it supplies a larger json response.
I could use a json parser, but I trust my site, lol.

The dataFilter and complete complete callbacks were unused by the
validation plugin, so free to use.
Since complete is called no matter what, you need to manually check
for success, since it succeeds as long as
the response exists and doesn't equal false, that's not to hard.
The dataFilter is called before jQuery parses the response, so you
need to parse it yourself, however you need to.

But this solution expands the form plug-in functionality by lots.  At
least if the response is successful.  Since it
specifically checks if the response is "false" on fail, you can't send
anything else but that.

-Adam




On Apr 8, 9:13 pm, phazei <pha...@gmail.com> wrote:
> Jörn, or anyone else familiar with the jQuery validator and ajax
>
> I am making a form that asks for the persons address, but when they
> type in the zip code, I need to both check it from in a db and make
> sure it's listed, and if it is, return the city and state.
>
> I figured out the validator needs the ajax to specifically return the
> text 'false' to be invalid, and anything else evaluates to valid.
>
> But I need to take the response data and do stuff with it.  I tried
> using:
> remote: { success: function(){ ... } }
> But it overwrites the default one.  I tried copying all the data from
> the default into mine, but nothing happened then.
>
> I was able to .bind ajaxSuccess to the body, but if I alert
> (response.toSource()), it shows data:(void 0) no matter what and
> undefined if I alert(response.data).
>
> I can use:
> remote: { complete: function(){ ... } }
> But it doesn't have the data
>
> How can I get the data back to play with without modding the validate
> class?  I can use the complete call back if I can get the data.  If I
> do need to mod it, I was just going to throw it into a global var at
> the beginning of the success call.
>
> Help,
>   Adam

Reply via email to