2010-10-05 74 views
0

後返回true正確的值,我試圖找到wheather在數據的基礎上它總是如此的回報存在於第一次嘗試始終在第一個調用返回第一個電話

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; 
} 

回答

0

AJAX是異步
您的return語句在服務器回覆之前運行。

您不能使用return語句;你需要回調(如$.ajax)。

+0

是否有任何我可以看看的例子... – dsadsad 2010-10-05 02:06:28

0

我不確定&在var pars = '&email=' + email; 這個&是abit奇怪嗎?
你錯了,當使用return IsEmailExistinInthemo;這樣,函數立即返回阿賈克斯更新回報預期

var IsEmailExistinInthemo = true; 

設置阿賈克斯更新後的true,沒有價值;

相關問題