I am trying to use the FormData object to send a series of fields, both file and non-file, to a PHP endpoint on my server. However, no matter what I've done, the $_REQUEST
superglobal is always blank within the PHP endpoint. The code I'm using to send the FormData is below.
const formData = new FormData();
formData.append('token', this.props.token);
formData.append('id', this.props.id);
formData.append('name', this.props.name);
formData.append('imageFile', this.props.image);
formData.append('entryFile', this.props.file);
formData.append('license', this.props.license);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://path/to/endpoint', true);
xhr.send(formData);
You might need something like
xhr.open('POST', 'https://path/to/endpoint', true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(formData);