I've encountered an issue with my code and I'm struggling to pinpoint the exact problem.
In this particular section involving AJAX, I am trying to send a file from a form along with an argument to my node.js server:
var layerID = 2;
var formData = new FormData($("#formid")[0]);
formData.append('layer', layerID);
$.ajax({
url: "http://localhost:3000/file-upload",
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false
});
Additionally, there is this part using Express which is supposed to accept the file and the argument:
app.use(bodyParser.urlencoded({
extended: false
}))
app.post('/file-upload', function (req, res) {
console.log('params: ' + req.params);
console.log('body: ' + req.body);
console.log('query: ' + req.query);
upload(req, res, function (err) {
if (err) {
errorHandler
return
} else {
successHandler
}
})
})
The issue lies in the fact that while the file is being received correctly, the 'layer' argument is not being received by my node.js server.