Samad,

AJAX calls are asynchronous and will run outside the context of the current
function. 

So, while the AJAX call might get invoked, the function will continue to run
in parallel with the AJAX call.

The only way to get the script to run like you have it would be to specific
run the AJAX call as "synchronous"--which is a really bad practice.

The better way to do this is to figure out what AJAX validation you need to
do and then run them all via one request. Once the AJAX validation result
has come back, you finish process the validation via a callback.

-Dan

>-----Original Message-----
>From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
>Behalf Of Samad
>Sent: Thursday, July 26, 2007 3:27 PM
>To: jQuery (English)
>Subject: [jQuery] Re: Form Client and server side validaion probleme
>
>
>Bump!
>
>No one can help me ??
>
>On 25 juil, 22:46, Samad <[EMAIL PROTECTED]> wrote:
>> Hello,
>>
>> I'm trying to fix a validation form probleme but I don't have any
>> idea.
>>
>> This is the probleme :
>>
>> I have a forum with inputs, for the validation, I have some client
>> side controls and server ones with an ajax call.
>> this is the code :
>>
>> -------------------------------------------------------------------------
>-------------------------------------------------------------
>>         $("#Register").submit(function() {
>>
>>                         $(".ErrorDiv").hide();
>>                         $(".SuccessDiv").hide();
>>
>>                         var msg_error = 0;
>>
>>                 var valid_email = /^\w+([\.-]?\w+)[EMAIL PROTECTED]([\.-
>]?\w+)*(\.\w{2,3})
>> +$/;
>>                 var valid_text = /^\w+$/;
>>
>>                 var username = $("#Username").val();
>>                 var email = $("#Email").val();
>>                 var pwd = $("#Password").val();
>>                 var pwd_conf = $("#PasswordConf").val();
>>
>>                 if ( !username.match(valid_text)  || username == "" ) {
>>
>>                                 msg_error = 1;
>>                         $("#Username_Error").show();
>>
>>                         } else {
>>
>>                                 $.ajax({
>>                             type: "POST",
>>                             url: "inc/user_reg.hand.php",
>>                             data:
>"action=check_username&username="+username,
>>                             dataType: "html",
>>                             success: function(msg){
>>
>>                                                 if (msg == "KO") {
>>                                                         msg_error = 1;
>>
>$("#UsernameUsed_Error").show();
>>
>>                                                 }
>>
>>                             }
>>                     });
>>
>>                         }
>>
>>                 if ( !email.match(valid_email) || email == "" ) {
>>
>>                                 msg_error = 1;
>>                         $("#Email_Error").show();
>>
>>                         } else {
>>
>>                                 $.ajax({
>>                             type: "POST",
>>                             url: "inc/user_reg.hand.php",
>>                             data: "action=check_email&email="+email,
>>                             dataType: "html",
>>                             success: function(msgmail){
>>
>>                                                 if (msgmail == "KO") {
>>                                                         msg_error = 1;
>>
>$("#EmailUsed_Error").show();
>>
>>                                                 }
>>
>>                             }
>>                     });
>>
>>                         }
>>
>>                 if ( !pwd.match(valid_text)  || pwd == "" ) {
>>                         msg_error = 1;
>>                         $("#Password_Error").show();
>>                         }
>>
>>                 if ( pwd != pwd_conf ) {
>>                         msg_error = 1;
>>                         $("#PasswordConf_Error").show();
>>                         }
>>
>>                 if( msg_error == 0 ) {
>>
>>                     $.ajax({
>>                             type: "POST",
>>                             url: "inc/user_reg.hand.php",
>>                             data: "action=register&username="+username
>> +"&email="+email+"&password="+pwd,
>>                             dataType: "html",
>>                             beforeSend: function(msgregister){
>>
>>                             },
>>                             success: function(msgregister){
>>
>>
>$("#Register_Success").show();
>>                                                 bindStyle();
>>
>>                             }
>>                     });
>>
>>                         }
>>
>>                 return false; // cancel conventional submit
>>
>>         });
>>
>> -------------------------------------------------------------------------
>-------------------------------------------------------------
>>
>> The thing is : when I try the ajax call the first time with the
>> 'Username' and after a 'KO' response, the variable msg_error is still
>> on '0' and not '1' even if the msg received after the call is 'KO'
>> and the "#UsernameUsed_Error" is showed.
>>
>> Can anyone help ?? :)


Reply via email to