javascript - Animate TR to disappear on ajax request -


i using bootbox create following modal:

$("a.delete").on("click", function() {     var id = $(this).attr('id').replace('item_', '');     var parent = $(this).parent().parent();     var table = $(this).attr('rel');     bootbox.dialog({       message: "are sure want delete entry?",       title: "delete confirmation",       buttons: {         success: {           label: "yes",           classname: "btn-danger",           callback: function() {              $.ajax({                 type: "post",                 url: "",                 data: 'deleteitem=' + id + '&table=' + table,                 beforesend: function () {                     parent.animate({                         'backgroundcolor': '#e3e3e3'                     }, 400);                 },                 success: function (msg) {                     if (msg == "success") {                         $('#projects').datatable().row(parent).remove().draw();                         $("html, body").animate({                             scrolltop: 0                         }, 600);                         count();                     } else if (msg == 'last') {                         $('#rld_div').load("<?php echo $_server['request_uri']; ?> #rld_div");                     } else {                         bootbox.alert(msg);                     }                     count();                 }             });           }         },         danger: {           label: "no",           classname: "btn-primary"         },       }     }); }); 

html:

<a href="javascript:void(0);" class="delete" rel="projects" id="item_206678293">delete project</a> 

it strips id id of <a> , and gets name of table rel. seems working parent (namely tr), not animate , disappears

when log var parent [tr.odd, prevobject: m.fn.init[1], context: a#item_250558768.delete] seems selecting right object. doing wrong?

if you're after closest parent <tr> (assuming link in table row), use parents('tr') (note 's').

as far animation goes, i'm not sure beforesend let modify dom - the manual makes seem it's purpose allow modify xmlhttprequest object before request made. might make more sense move animation outside ajax request, , make request in "complete" callback animation.

if seems workable, can code using $.post helper instead of $.ajax:

parent.animate({ 'backgroundcolor': '#e3e3e3' },      400,     function(){         var data = {              deleteitem : id,              table: table          };          $.post(url, data)             .done(function (msg, jhr, status) {                 if (msg == "success") {                     $('#projects').datatable().row(parent).remove().draw();                     $("html, body").animate({                         scrolltop: 0                     }, 600);                     count();                 } else if (msg == 'last') {                     $('#rld_div').load("<?php echo $_server['request_uri']; ?> #rld_div");                 } else {                     bootbox.alert(msg);                 }                 count();             });     });   

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -