这是表单html代码。我enctype="application/x-www-form-urlencoded"
目前正在使用。
<form name="{{this.status}}" class="commonForm" enctype="application/x-www-form-urlencoded" action="/api/upload/{{this.commonID}}" method="post">
<td>
<input type="file" id="{{this._id}}" class="form-control" name="FileUploadForClient" multiple required {{this.statusDisabled}} />
</td>
<td>
<button type="submit" class="btn btn-primary btn-block col-sm-2" style="font-size:16px" {{this.statusDisabled}}>Submit</button>
</td>
</form>
我的 AJAX 调用:
var formData = new FormData(this);
formData.append('text',"Awesome Font!");
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: formData,
processData: false,
contentType: false,
dataType: "json",
success: function(response){
if (response.status == '200') {
$.LoadingOverlay("hide");
swal({
title: "Excellent!",
text: "Files submitted successfully!",
icon: "success",
button: "Ok",
showCancelButton: true
}).then((result) => {
if (result) {
window.location.reload();
}
});
我想将上面附加的文本字段与上传的文件一起发送。文件已成功提交,但是当我尝试在其中使用req.body.text
时,nodejs
它给出了未定义。为什么?????????????
这是路线代码:
router.post('/api/upload/:cid',function(req,res,next){
console.log("yes it came under api");
console.log("req.body.text = " + req.body.text + req.query.text);
upload2(req,res,function(err) {
if(err) {
console.log("Error is important = "+ err);
}
else
{
console.log("Uploaded");
}
})
})
所以我的主要问题是:如何在使用???nodejs
发送后访问服务器端的文本字段 请帮忙!!!AJAX
FormData