Why not sent the data?

Trying to send form data with formData()

Here is my form:
<form action="" enctype="multipart/form-data">
 <input class="name" name='name' type="text" placeholder="Name">
 <input class="phone" name='phone' type="text" placeholder="Phone">
 <input class="mail" name='mail' type="text" placeholder="E-mail">
 <textarea class="ms" name='message' placeholder="Message"></textarea>
 <div class="checkbox-area">
 <input class="input" class="rules" id='rules' type="checkbox" value='yes' />
 <label for="rules">I have read the terms of use</label>
 <div class="file-area">
 <input class="file" name="file" type="file" id='file' multiple="true">
 <label for="file">Upload files</label>
 <button type="submit">Send</button>

That's going to send (the key is setting the title.):

if (method === 'POST') {
 request.open(method, url, async);
 request.setRequestHeader('Content-Type', 'multipart/form-data; boundary=something');
 request.send(this._createQuery(paramsObj, method));

//Looks like _createQuery method for POST sakprosa
//It generates the request itself, specifically the information you want to send
//Problems with this method no console.log(data.get(key)); - I checked whether there is the recorded value
//And the values are written correctly, it can be seen in the screenshot below

_createQuery(paramsObj, method) {

 if (method === 'GET') {
 let query = ";

 for (let key in paramsObj) {
 query += `${key}=${paramsObj[key]}&`;

 return query.substring(0, query.length - 1);
 } else {
 let data = new FormData();
 for (let key in paramsObj) {
 data.append(key, paramsObj[key])

 return data;


A screenshot of the data to formData()


In the end, the request has been successfully sent data like this:

But the title of the request is not the one I was prescribed (
request.setRequestHeader('Content-Type', 'multipart/form-data; boundary=something');


And when I check in the PHP file that I have in $_POST, I get an empty array:

What could be the problem? I think in the header, but do not know what to prescribe
April 3rd 20 at 17:42
0 answer

Find more questions by tags AJAXJavaScript