2014-01-30 122 views
1

我正在使用:http://www.jquery-steps.com/在我的項目中。一個用於添加嚮導的好的Jquery插件。異步驗證

我想做一個服務器驗證,如果電子郵件存在於服務器上。如果它無效,巫師必須保持同一步驟。如果它有效,嚮導應該轉到下一步並獲取與電子郵件相關的信息。

我想這對

 onStepChanging: function (event, currentIndex, newIndex) { 

      event.preventDefault(); 
      var action = ... 
      ... 

      if (currentIndex == 1) { 
       var form = null; 
       if (action === "import") { 
        form = $("#link-account-form") 
       } 
       else if (action === "create") { 
        form = $("#create-profile-form"); 
       } 


       form.validate().settings.ignore = ":disabled,:hidden"; 
       var formValid = form.valid(); 
       if (formValid && newIndex == 2) { 
        if (action === "import") { 
         var login = form.find(".temp-login").val(); 

         // here I want to get async validation to work... 
         return $app.getUserByLogin(login, function (userAccount, status, xhr) { 
          if (userAccount != null) { 
           $("#thirdStep .temp-name").val(userAccount.user.name); 
           $("#thirdStep .temp-gender").val(userAccount.user.gender); 
           var birthday = UI.Formatter.parseDatetime(userAccount.user.birthday); 
           $("#thirdStep .temp-birthdate").data('datetimepicker').setLocalDate(birthday); 
           $("#thirdStep .temp-telephone").val(userAccount.user.phone); 
           $("#thirdStep .temp-cellphone").val(userAccount.user.cellPhone); 
           $("#thirdStep .temp-address").val(userAccount.user.address); 
           $("#thirdStep .temp-neighborhood").val(userAccount.user.neighborhood); 
           $("#thirdStep .temp-zipcode").val(userAccount.user.zipCode); 
           $("#thirdStep .temp-city").val(userAccount.user.city); 
           $("#thirdStep .temp-state").val(userAccount.user.state); 
           $("#thirdStep .temp-id").val(userAccount.user.id); 
           $("#thirdStep .temp-picture-url").val(userAccount.user.pictureUrl); 
           return true; 
          } else { 
           UI.Notify.error("", $("#res").data("retrieve-error")); 
           return false; 
          } 
         }).fail(function (data, status, xhr) { 
          UI.Notify.error("", $("#res").data("retrieve-error")); 
          return false; 
         }); 
        } 
        else if (action === "create") { 
         ... 
         return true; 
        } 
       } 
       return formValid; 
      } 
      return true; 
     } 

你已經面對這種情況呢?你怎麼做的?

回答

0

我解決了$ app.getUserByLogin中的ajax請求上使用async:false的問題。感謝您的關注。