[英]HTML form to XMLHttp request
I am trying to take the following form and convert it to use XMLHttp. 我正在尝试采用以下形式并将其转换为使用XMLHttp。 Cannot get a working example of how to convert this to use XMLHttp.
无法获得如何将其转换为使用XMLHttp的有效示例。
<form enctype='multipart/form-data' action='process.do'>
<input id='myfile' type='file'>
<input type='hidden' name='systemid' value='a1312423r1rde223e423e'>
<input type='hidden' name='systemname' value='My value'>
</form>
var x = new XMLHttpRequest()
x.open('POST', 'process.do');
// Where to add systemid, systemname parameters?
x.send($('myfile').files[0])
Just send()
a FormData object instantiated from the form object. 只需
send()
从表单对象实例化的FormData对象。
var x = new XMLHttpRequest()
x.open('POST', 'process.do');
x.send(new FormData(document.querySelector("form")));
That will include all the data from the form. 这将包括来自表单的所有数据。
You'll need to give your file input a name
though. 不过,您需要给文件输入一个
name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.