tags:

views:

51

answers:

2

I am trying to find wheather exists in data base it always true returns on first attempt

var IsEmailExistinInthemo = true;
function EmailRegVerify(email) {
    var url = '/_service/setVerifyProfiles.ashx';
    var pars = '&email=' + email;
    var target = 'output-div';
    var myAjax = new Ajax.Updater(target, url, { method: 'get', parameters: pars,
        onSuccess: function(transport) {
            var response = transport.responseText || "no response text";
            if (response == "True") {
                $('errorMsg_Email').show();
                $('errorMsg_Email').innerHTML = 'Email address has already been registered with IntheMO';
                IsEmailExistinInthemo = false;
            }
            else {
                $('errorMsg_Email').hide();
            }
        },
        oncomplete:function(){

        },
        onFaliure: function() {
            //msg: something went wrong
        }
    });
 return IsEmailExistinInthemo;
}
A: 

AJAX is asynchronous.
Your return statement runs before the server replies.

You cannot use a return statement; you need to take a callback (like $.ajax does).

SLaks
Is there is any example i can look into ...
dsadsad
A: 

I'm not sure about & in var pars = '&email=' + email; this & is abit strange?
And you wrong when use return IsEmailExistinInthemo; like this, function immediately return the true of

var IsEmailExistinInthemo = true;

after setup Ajax Update, not the value that Ajax Update return as expected;

pinichi