It has actually a very simple answer.
The function is returning the string rather than a
appendChild can only append the node.
So for example, if you try to do just appendChild the string:
var s = '<p>test satu dua tiga</p>'; // is the string
This above code will never work. What will work is as below:
var s = document.createElement('p'); // is the node
s.innerHTML = 'test satu dua tiga';
This will happen if you accidentally are not dragging a element that does have the id assigned (example you are dragging a surrounding element). In that case an ID is empty and your function drag() is assigning an empty value which is then passed to the drop() and it fails there.
So you should try assigning the ids to all of your elements, including your tds, divs, or whatever is around the draggable element.
Hope above solutions will fix your issue.