【发布时间】:2019-11-03 11:01:45
【问题描述】:
我有一个带有 src="fast.jpg" 的 img 标签。我想从我的源文件夹中获取图像,将其添加到表单数据并通过 http post call 发送
html:
<img src="fast.jpg" data-highres="fast.jpg"
style="width:150px;height:150px;"id="img1" onclick="myFunction(this);" >
javascript:
var img = document.getElementById($(target).attr("id")).src
console.log("img>>>>",img)
var files = img.files
console.log("files", files)
var formData = new FormData();
formData.append('pic[]', img.name);
console.log("formdata>>", formData)
通话后:
xhttp.open("POST", "http://127.0.0.1:5001/testpost", true);
xhttp.withCredentials = false;
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.setRequestHeader("cache-control", "no-cache", "no-cors");
xhttp.send(formData);
【问题讨论】:
标签: javascript jquery form-data