2014-01-30 88 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的问题。感谢您的关注。