Lưu ý: mã bên dưới chỉ để trình diễn và tôi đang sử dụng plugin xác thực jQuery và jQuery.Cách vô hiệu hóa các trường theo cách thủ công sau khi cuộc gọi AJAX với jQuery xác nhận
Giả sử tôi có một mẫu với hai lĩnh vực (email và số hàng tồn kho):
<form action="/something" method="post" id="demoForm">
Inventory No: <input type="text" class="required" name="inventory_no" />
Email: <input type="text" class="required" name="email" />
<input type='submit' value='submit' />
</form>
Binding plugin để có dạng:
jQuery(function(){
jQuery('#demoForm').validate();
});
//handle user submit
jQuery('#demoForm').bind('submit', function (e) {
e.preventDefault();
if (jQuery(e.target).valid()) {
//form is valid submit request thru ajax
jQuery.ajax({
/*more options here*/
success: function (data) {
/*
Server process request and finds that, email is already in use
and inventory number is invalid
so it sends data in some format may pe JSon
with field names and message indicating errors
eg: Email:"Already in use"
InventoryNo: "Invalid Inventory No",
Now can i invalidate these two fields on form mannualy
and display the message received from server for each field
*/
}
});
}
});
Bạn đã bao giờ tìm được giải pháp cho điều này chưa? Đó là chính xác những gì tôi đang cố gắng làm vào lúc này. – Richard
tôi tìm thấy một giải pháp cho điều này chỉ cần cho tôi một thời gian, tôi sẽ cho u biết –