Gareth,

In order to get this to work the way you have it, you'd have to do a
"synchronous" call to the server, which wouldn't be AJAX (the "A" is for
asynchronous.) :)

Because the code you have is running asynchronously, the AJAX call is fired
off and then the validation routine continues on its way. However, when the
server responds back, your callback function runs--which displays the alert.

You should be able to do a synchronous call using the $.ajax() function, but
it's pretty much always a bad idea to rely on synchronous operations (since
if something happens during the transmission--it can really cause problems.)

For asynchronous validation, I'd recommend doing those as a separate remote
call and then have once the validation returns, have it fire off the rest of
the local validation. You could build a queuing of remote validation rules
that get fired off and once all the rules have returned, run the local
validation.

Just be aware that AJAX validation can really cause UI issues if the server
is unresponsive.
 
-Dan



>-----Original Message-----
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
>Behalf Of Gareth Hughes
>Sent: Tuesday, March 20, 2007 4:52 PM
>To: jQuery Discussion.
>Subject: [jQuery] Validation plugin: on blur using ajax
>
>I've been playing with Jörn's excellent validation plugin (beta 2) to try
>and get it to validate individual fields using ajax on blur. It's a pretty
>basic attempt (because I'm sure Jörn is going to do something much better
>soon :), but I've got stuck and I can't fathom out why. I've added a new
>method called remote that I call in my rules like this:
>
>headerx: {remote: "/gen/valid.cfm"}
>
>And in the validate.js the new method looks like this:
>
>remote: function(value, element, remoteurl) {
>$.getJSON(remoteurl+"?value="+value,
>function(data){
>//alert(data.SUCCESS);
>if(data.SUCCESS == 'true'){
>return true;
>}
>});
>},
>
>It works to point; the validation page is called and the value is passed
>correctly, the validation page does its stuff and passes back true or false
>depending on the result being good or bad and the alert displays the
>correct
>true/false result. But, I can't seem to get the 'if' statement to work and,
>even if I put 'return true' above the 'if' (but below the $.getJSON) it
>always returns false.
>
>This is the first time I've used jQuery so A) I'm pretty pleased I got this
>far and B) if what I'm doing looks stupid, please forgive me :)
>
>If anyone can offer a clue I'd appreciate it.
>
>Thanks
>
>Gareth
>
>
>_______________________________________________
>jQuery mailing list
>[email protected]
>http://jquery.com/discuss/



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to