Hi, Ajax requests are *asynchronous*; more in this recent thread: http://groups.google.com/group/prototype-scriptaculous/browse_thread/thread/6b593cf7e6be236c/bf42fddc38f2d8c5
HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Jan 26, 6:58 pm, RobDiablo <[email protected]> wrote: > Hello, > > I'm having a weird issue when trying to use Ajax.Request in a function > within a function. > > I'm using LiveValidation fromhttp://www.livevalidation.com/which > uses prototype.js. It has a custom attribute that allows you to pass > in a custom function to validate against. I call this custom function > so that I can check a username against a database using the > Ajax.Request method. > > The way it should work is, if the username is not found, it returns > true, otherwise false. I haven't been able to get that exact result > so I've created some workarounds. True or False is passed to the > custom function of LiveValidation and validates based on true or > false. > > However, for some reason, there is a delay in passing the value from > the LiveValidation custom function. So let's say the username bee is > taken. As I type the word 'bee' and the LiveValidation is being > passed to the Ajax.Method, it is returning false. If I continue to > type, let's say to the word 'beer,' it finally comes back true, even > though 'beer' is not taken. Once I leave that field for the next one, > it validates again and comes back false for the word 'beer.' Thus the > delay. > > Here is the code I am using for the Ajax.Request function: > > ***************************************** > function validateEntry(c,f) { > var url = "ajaxProcessor.php?f=" + f + "&c=" + c; > new Ajax.Request(url, { > method: 'post', > onComplete: function(transport) { > if (transport.responseText == "YES"){ > return entryResponse = 1; > }else{ > return entryResponse = 0; > } > } > }); > if (entryResponse == 0) { > return false; > }else{ > return true; > }} > > **************************************** > I'm using entryResponse because I haven't figured out how to return > true or false. > > Here is the custom function for LiveValidation: > > **************************************** > <script type="text/javascript"> > > var f1 = new LiveValidation('f1', { validMessage: "Ok!" } ); > f1.add( Validate.Custom, { against: function(value){ return > validateEntry(value,3) }, failureMessage: "Username already > taken!" } ); > > </script> > ******************************************* > > Now I tested to see if it was the LiveValidation that was causing the > delay in sending the correct value to the Ajax.Request function and > it's not. Somewhere within the Ajax.Request method, the return values > are being delayed. > > Can anyone help? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
