所以我有一个表单:
<form id="myForm" enctype="multipart/form-data">
<input id="name" title="name" type="text" placeholder="name" />
<input id="quantity" title="quantity" type="text" placeholder="quantity" />
<input id="price" title="price" type="text" placeholder="price" />
<input id="imageLocation" title="imageLocation" type="text" placeholder="imagelocation" />
<input id="description" title="description" type="text" placeholder="description" />
</form>
这里是我发送数据的地方:
function postMultiPartHttpCall() {
var XHR = new XMLHttpRequest();
var form = document.getElementById("myForm");
var FD = new FormData(form);
XHR.addEventListener("load", function (event) {
var callingObj = {};
callingObj.responseText = event.target.responseText;
console.log(callingObj);
});
XHR.open("POST", '/articlePost');
XHR.send(FD);
}
这是我接收到它的地方:
function _processFormData (request, res, onSuccess,onError) {
var requestBody = '';
request.on('data', function (data) {
requestBody += data;
if (requestBody.length > 1e7) {
res.writeHead(413, 'Request length too long', { 'Content-Type': 'text/html' });
res.end('413 : Request Entity Too Large');
}
});
request.on('end', function () {
var oFormData = qsLib.parse(requestBody);
console.log(request.headers);
});
}
当我发送一些数据时,我会收到这个(console.log):
Debugger listening on 127.0.0.1:5858
Server was started
{ host: 'localhost:1337',
connection: 'keep-alive',
'content-length': '44',
origin: 'http://localhost:1337',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryyVFw7KZwIaAIQeQ1',
accept: '*/*',
referer: 'http://localhost:1337/CartSPA.html',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.8,hr;q=0.6,de-AT;q=0.4,de;q=0.2,de-DE;q=0.2' }
我想要的是在不使用expressJS或其他类似的第三方库的情况下,获取表单字段的对象。是否可以使用边界数字来获取属性,或者在哪里可以看到发送了哪些数据?