I was calling it twice in a process with timers/intervals….
Solution 1 :
Problem :
I am trying to download a locally generated json with this code:
function downloadJson(data, name) {
let dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute('href', dataStr);
downloadAnchorNode.setAttribute('download', name);
document.body.appendChild(downloadAnchorNode);
downloadAnchorNode.click();
downloadAnchorNode.remove();
}
downloadJson({foo: "bar"}, "example.json");
But for a reason it is downloading 2 copies of the same json. Does anybody knows what is happening?
Comments
Comment posted by Barmar
It only downloads once here. Are you sure you’re not running the function twice? Add a
Comment posted by blex
That piece of code works once. I think the problem is where you call that
Comment posted by Roko C. Buljan
To me it downloads only once. Perhaps you’re calling it twice? Do a quick CTRL+F for
Comment posted by Rogelio Gámez
Thank you guys, it was a problem with some parallel processing I was doing.