I’m making signup form stuff and I want to save data to server and I got this code :
JavaScript
x
13
13
1
function Signup()
2
{
3
var text = "hello world",
4
blob = new Blob([text], { type: 'text/plain' }),
5
anchor = document.createElement('a');
6
7
anchor.download = "hello.txt";
8
anchor
9
anchor.href = (window.webkitURL || window.URL).createObjectURL(blob);
10
anchor.dataset.downloadurl = ['text/plain', anchor.download, anchor.href].join(':');
11
anchor.click();
12
}
13
But its download file and I’m wondering how to save/download it to server.
Advertisement
Answer
You can’t.
The code you have found is for triggering a download and saving a file to the browser’s download directory (client-side).
It would be a serious security risk for a web browser to be able to write to arbitrary files on the server.
Instead, create a web service (using the server side programming language of your choice) and make an HTTP request to it (e.g. by submitting a form or using fetch
).
Note that for a sign up system, you are almost certainly going to want to save the data to a database and not to a file (that is still a matter for server-side code though).