You are probably getting a php error. You would either need to log all php errors and then check the web server’s error log or check the network response tab in the browser’s developer tools.
However, I found that using .catch(console.error); prevents the normal display of this information, in Chrome, and I wasn’t interested in trying to track down why. Replace the line with the .catch on it with the following (found here - https://developers.google.com/web/updates/2015/03/introduction-to-fetch and modified by me to treat the returned data as text) -
}).then(
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
// Examine the text in the response
response.text().then(function(data) {
console.log(data);
});
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});
This will console.log any output from the web page and it also lets the developer tools network response tab ‘work’.
Your php code must ALWASY test and validate the submitted form data before using it. For a file upload you should -
Test if a post method form was submitted before accessing any of the form data.
If the total size of the form data exceeds the post_max_size setting, the $_FILES array will be empty. You would test for this condition next and setup a user error message telling the user what was wrong with the data that they submitted.
If the $_FILES array is not empty, you would then test the [‘error’] element and only use the uploaded file information if it is a zero (UPLOAD_ERR_OK).
For other error values that the user can do something about (UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_NO_FILE), you would set up user error messages telling the user what was wrong with the data that they submitted.
You would then perform any other validation tests on the uploaded file, setting up user error messages telling the user what was wrong with the data that they submitted.
If there are no validation errors, you would then move the uploaded file to the final location.
Any server-side validation errors should be formatted into a specific json response and be returned to the client-side code for it to test and display.
@igor_g, when using the FormData() object, outside of what’s needed to reference the correct form in the document, none of the form tag attributes matter.