Is it possible to generate a file with javascript and send it to server?

↘锁芯ラ 提交于 2020-01-05 03:08:27

问题


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!


回答1:


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);


来源:https://stackoverflow.com/questions/31592127/is-it-possible-to-generate-a-file-with-javascript-and-send-it-to-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!