When a document is written it changes something called the DOM (Document Object Model). If you add things to the document via javascript then parts of the DOM don't get updated. One thing that doesn't is document / script references. As far as the document is concerned, the item:
'<button id="btn" onclick="getdata()">GET</button>'
is just an element without javascript.
You can create your own javascript references by adding the event within javascript:
document.getElementById("btn").addEventListener("click", function(e) {
getdata()
});