Successfully sending a file to the server for processing using the code below:
var formData = new FormData();
formData.append('file', $('#fileUpload')[0].files[0]);
options = JSON.stringify(options); // {"key": "value"}
$.ajax({
url: "url",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function (data) {
},
error: function (msg) {
showMsg("error", msg.statusText + ". Press F12 for details");
console.log(msg);
}
});
However, I want to send both FormData and a json object. Attempting something like this:
var formData = new FormData();
formData.append('file', $('#fileUpload')[0].files[0]);
options = JSON.stringify(options); // {"key": "value"}
$.ajax({
url: "url",
type: "POST",
data: { "formData": formData, "options": options },
//dataType: "json",
//processData: false,
//contentType: false,
success: function (data) {
},
error: function (msg) {
showMsg("error", msg.statusText + ". Press F12 for details");
console.log(msg);
}
});
Encountering an Uncaught TypeError Illegal invocation error message. Research suggests no examples of sending form data this way. Is there a need for restructuring or another method to send a json object with form data?