Thursday, May 12, 2016

jQuery, prevent many click fireup





Use jQuery function die to prevent many clicks fire at the same time:
example
                $('#popup_9sp .modal-body .delete').die('click');    
                $('#popup_9sp .modal-body .delete').live('click', function(){
              
                        var id = $(this).parents('tr').attr('data-id');
                        var answer = confirm("Are you sure to delete this row?")
                        if(id>0 && answer){
                          
                              $('#tab1').find('.cid'+id).remove();
                        
                        }        
                        var postdata = {funct: 'DeleteCourse', id:id};
                        var url = '../_ajaxParts/preplanning/preplanning_summary.php';

                        if(id>0 && answer){
                            $.post(url, postdata, function(data) {
                                if(data=='fail')
                                    $("div#notice").html('Delete failed!');
                                else{    
                                    $("div#notice").html('Delete successfully.');
                                }
                                                                                
                                $("div#notice").css('display', 'block');
                                $("div#notice").fadeOut(15000);
                            });
                        }                      
                        if (answer)
                            $(this).parents('tr').css('display','none');
                    });
                  
      

            });

No comments:

Post a Comment