是否可以使用javascript生成文件并将其发送到服务器?

问题描述:

是否可以使用javascript生成文件并将其发送到服务器?我的网页中有一个部分,用户可以在其中修改页面的样式,并且我想在将样式文件发送到服务器之前使用该样式配置生成css文件.这可能吗?谢谢!

Is it possible to generate a file with javascript and send it to server? I have a section in my web page where the user can modify the style of its page, and I want to generate the css file with that style configuration before to send it to the server. Is this possible? Thanks!

var blob = new Blob(["css content"],{type:"text/css"});
var formData = new FormData()
formData.append("file",blob,"fileName"); 
var xhr = new XMLHttpRequest();
xhr.open('POST', '/server', true);
xhr.onload = function(e) { /**get answer from server*/};
xhr.send(formData);