How can I delete a row in the view only if the AJAX call & db deletion was successful?
        Posted  
        
            by 
                user1760663
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1760663
        
        
        
        Published on 2012-10-19T22:43:11Z
        Indexed on 
            2012/10/19
            23:01 UTC
        
        
        Read the original article
        Hit count: 189
        
I have a table where each row has a button for deletion. Actually I delete the row everytime without checking if the ajax call was successfull. How can I achieve that, so that the row will only be deleted if the ajax call was ok.
Here is my clickhandler on each row
$("body").on('click', ".ui-icon-trash" ,function(){
    var $closestTr = $(this).closest('tr');  // This will give the closest tr
                            // If the class element is the child of tr          
    deleteRowFromDB(oTable, closestTr);
    $closestTr.remove() ;  // Will delete that
 });
And here my ajax call
function deleteRowFromDB(oTable, sendallproperty){
        var deleteEntryRoute = #{jsRoute @Application.deleteConfigurationEntry() /}
        console.log("route is: " + deleteEntryRoute.url)
        $.ajax({
           url: deleteEntryRoute.url({id: sendallproperty}),
           type: deleteEntryRoute.method,
           data: 'id=' + sendallproperty
        });
© Stack Overflow or respective owner