I'm trying to create an ajax upload form that sends both a file and a text input. I've managed to send the file with the following code:
var $form = $('#form');
var formData = new FormData();
formData.append('file', $('#file')[0].files[0]);
$.ajax({
url: 'upload.php',
type: 'POST',
dataType: 'html',
data: formData,
processData: false,
contentType: false
});
However, I also need to send the text input, so I've tried passing the whole form to the FormData
object:
var $form = $('#form');
var formData = new FormData($form);
$.ajax({
url: 'upload.php',
type: 'POST',
dataType: 'html',
data: formData,
processData: false,
contentType: false
});
But then I get nothing in 'upload.php'
How can I send the text and the file inputs together?
Thanks!