2013-02-27 92 views
0
$(document).ready(function(){ 

$('#send').click(function() { 

var names = $('#appontment_form').serialize(); 

//this is how my names variable look like 
//doctor=Dr.Fathmath+Shahuda&date=2013-02-27&time=1900+-+1700&phone= 

var doc = $(names).filter('doctor'); 

if(doc !='') 
{ 
     $.ajax({ 
     type: "post", 
     url: "../../includes/jqueryRequireFiles/appointmentSave.php", 
     data:names, 
     success: function(data) 
     { 
     $('#confir').text('Your Appointment Received..'); 
     } 
     }); 
     return false; 
} 
}); 
}); 

我有一個appontment窗體。當我點擊發送鏈接時,它將獲取文本框中的所有值,並通過serialize()函數將其放入名稱變量中。我要篩選的名稱變量,找出是否有任何的領域留下未填寫。如果只有那麼我會讓阿賈克斯部分..但它不工作...任何幫助使用jquery serialize()函數進行簡單表單驗證

回答

1

當您使用$.serialize()時,變量內容看起來像?key=value1&key=value2。如果您想驗證的形式,只是做沒有像連載

var found_errors = false; 
if($('#formfield1').val().trim() == "") { 
    //Handle errors if field is empty 
    found_errors = true; 
} 

如果沒有發現錯誤,序列化表格併發送。