问题
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