[英]upload file from javascript to rails server
I want to upload an image to my Rails server (my front end uses Marionette.js). 我想将图像上传到我的Rails服务器(前端使用Marionette.js)。
It seems extremely simple, however I could not find any straightforward solution. 看起来非常简单,但是我找不到任何简单的解决方案。 There is a list of different solutions , but they all use third-party libraries and require complex workarounds.
有一系列不同的解决方案 ,但是它们都使用第三方库,并且需要复杂的解决方法。 Is there no easy solution to achieve something as simple as this?
没有简单的解决方案来实现像这样简单的事情吗?
I believe you can accomplish this with a simple XMLHttpRequest. 我相信您可以通过一个简单的XMLHttpRequest来完成此任务。 You can review the sample code form MDN here:
您可以在此处查看示例代码表单MDN :
function reqListener () {
console.log(this.responseText);
}
var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("get", "yourFile.txt", true);
oReq.send();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.