Ciao,
questo dovrebbe funzionare
codice:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$("#btn").click(function (e) {
var data = new FormData();
jQuery.each(jQuery('#documento')[0].files, function(i, file) {
data.append('documento', file);
});
$.ajax({
method: 'POST',
data: data,
cache: false,
contentType: false,
processData:false,
dataType: 'text',
url: 'invia.php'
});
})
})
</script>
<form name="demo" id="demo" method="POST" action="invia.php" enctype="multipart/form-data">
<input type="text" id="name" name="name" />
<input type="file" id="documento" name="documento" />
<button id="btn" type="button" >INVIO</button>
</form>
</body>
</html>
In grassetto le parti importanti.
Occhio che utilizzando un button, piuttosto che il submit, non serve il prevent default.