Tuesday, May 26, 2015

Freeze submit button when waiting ajax post data




When we update a input box from ajax post, it may delay. When users click the submit button, the old data will be posted.  We need to freeze submit button when waiting ajax post data.

Example:
$('#universalModal .modal-body input[name="StudentID"]').val(Obj.student_num);
$('#universalModal .modal-footer button#submitBtn').html('Save and Exit');

                   $('#universalModal .modal-footer button#submitBtn').prop("disabled", true);
                   $.post(url, postdata, function(data){
                        $("input[name='StudentID']").val(null);
                       $('#universalModal .modal-footer button#submitBtn').prop("disabled", false);       
                     }
                 });   



When the submit button is enables and we click submit button, the StudentID value is update from ajax post. Now we can post all form data vi submit.

No comments:

Post a Comment