I was trying to submit only specific inputs of a very large form and I wanted to do this using ajax. I had this and it was working fine. This will submit all inputs within #someDiv.
$(".save").click(function () {
dat = $.param($('#someDiv').find('input'));
$.ajax({
type: "POST",
url: "...",
data: dat,
success: function(data) {
//success
}
});
});
I then remembered that some of these inputs are file inputs so this will not work. I did some research and found that using FormData was the way to go:
$(".save").click(function () {
dat = new FormData($('#someDiv').find('input'));
$.ajax({
type: "POST",
url: "...",
data: dat,
processData: false,
contentType: false,
success: function(data) {
//success
}
});
});
But this function is not working, the success function is firing but nothing is saving so I assume the FormData is not being created properly. Any ideas? Thanks in advance