bevacqua / dragula

:ok_hand: Drag and drop so simple it hurts
https://bevacqua.github.io/dragula/
MIT License
21.89k stars 1.97k forks source link

How to cancel drag when jQuery make a ajax request return error #613

Closed jet10000 closed 3 years ago

jet10000 commented 5 years ago
           drake.on('drop', function (el, target, source, sibling) {
                $.post(
                    '/moveto/',
                    {
                        'handle': el.id,
                        'sibling': sibling.id,
                    },
                    function (data) {
                        drake.cancel(true);
                })
            }

drake.cancel(true) NOT WORK.

wayneforrest commented 5 years ago

This is not working for me too. However If I do not make an Ajax call I am able to cancel the drop, using drake.cancel(true);

If one makes a synchronous Ajax call, the drake.cancel(true) works. (But this is a bad idea.) e.g.

 drake.on('drop', function (el, target) {
            var data = {"Id":el.id, "Target":target.id};
            $.ajax({
            async: false, // <--- BAD but works...
            url: '/moveto/,
            type: 'POST',
            contentType: 'application/json; charset=utf-8',            
            data: JSON.stringify(data)
        }).done(function(result) {            
            drake.cancel(true);
        });