2012-09-27 86 views
1

我想让我的表单在ajax运行之前验证,但似乎无法获得编码的权利,因为这会发生。Ajax提交Spry验证

如果我它们分开,我可以张贴使用Ajax和不验证或验证,但其职位的默认方式

这里是我当前的代码我试图

$(document).ready(function(){ 
// ajax code start 
$('#form').on('submit', function (e){ 
    e.preventDefault(); 
    if (spry.widget.form.validate('#form') == true) 
    { 
    $.ajax({ 
     type: "POST", 
     url: "localProxy.php", 
     data: $('#form').serialize(), 
     success: function (response) { 
       document.location = '/thank-you'; 
       // do something! 
     }, 
     error: function() { 
       alert('There was a problem!'); // handle error 
     } 
    }); 
    }; 
}); 
}); 

回答

2

想通了

$(document).ready(function(){ 
// ajax code start 
$('#form').on('submit', function (e){ 
    e.preventDefault(); 
    Spry.Widget.Form.onSubmit = function(e, form) 
{ 
    if (Spry.Widget.Form.validate(form) == false) { 
     return false; 
    } 
    { 
    $.ajax({ 
     type: "POST", 
     url: "localProxy2.php", 
     data: $('#consult').serialize(), 
     success: function (response) { 
       document.location = '/thank-you'; 
       // do something! 
     }, 
     error: function() { 
       alert('There was a problem!'); // handle error 
     } 
    }); 
    }; 
    }; 
}); 
}); 
+0

感谢这有助于。 – tlaverdure