What do you think about getJSON for simple "is username available" type checks?

I'm thinking, go with the simple and more compact method. Return your errors in JSON and parse them out.

Since these are just quick "exists in database" lookups, the chances of failure are low. If they do fail, you lose the real time username check, but that should not matter, since when the form is fully posted, you are in a normal POST method, with normal client server validation, so the failure on the pure client side no longer matters. It's also the edge case, rare.

Form validation even with jQ validation plugins can quickly turn your code into a large set of conditions that's hard to maintain. I'm leaning on simpler is better.

As an aside, any suggestions on client side form validation being kept in parity with server side?

Consider email, username, and password validation done in jQ. That's three types of validation. Each has to have parity with your server side validation. Remembering to keep those in sync is a burden.

I would have a file that was validate.php?check=username&user=foo so one file can check all my form elements. Now when I get done on the client side, I'm considering using curl to fetch the same resource jQ did. This way my server side validation all comes from the same place.

It's an extra http call, so slower, and there's a window for some form of non atomic insert, although it's small, and my sites are not banks :)

Suggestions?
--
Scott
Iphone says hello.

On Sep 25, 2009, at 11:58 AM, MorningZ <morni...@gmail.com> wrote:

I'd suggest using the more generic $.ajax method so you can actually
catch the error, as the $.getJSON fails silently, which is no good for
programmers  :-(

Reply via email to