0

I am to post an Axios request because using get results in a 414 error. Here's the object:

rows= {
  0 : {
    "name":"Thor",
    "status":"active",
    "email":"[email protected]",
  },
  1 : {
    "name":"Mesa",
    "status":"active",
    "email":"[email protected]",
  },
  2 : {
    "name":"Jesper",
    "status":"stdby",
    "email":"[email protected],
  },
}

This is just a sample of the object's format. There is 400+ elements in the real one, thus post instead of get. I am having trouble properly building the form-data on this one. Here's what I have:

let data = new FormData();
Object.keys(rows).forEach(key => data.append(key, rows[key]));  //  <--- this doesn't do
data.set('target', target);  //  <---- this comes through just fine

axios({
  method: 'post',
  url: 'byGrabthorsHammer.php',
  data: data,
  headers: {'Content-Type': 'multipart/form-data'}
}).then(function(response) {
  if (response.error) {
    console.log('failed to send list to target');
    console.log(response);
  } else {
    console.log('response: ');
    console.log(response);
  }        
});

What comes through is just [Object][Object]' when ivar_dump($_POST);`. This is not what I want. How could I rewrite this properly so I get the data to the other side (like GET...).

0

2 Answers 2

2

Yow bro, POST Are for inserting new stuff, instead of doing a post you need a patch axios.patch it is basically the same. And it won’t fix your issue. To fix the issue you need to set the Content-Type to application/json, then on yow

axios.post(url, data: JSON.stringify(bigObject))
   .then(Rea=>Rea)
Sign up to request clarification or add additional context in comments.

2 Comments

m'okay. didn't even consider this... if you have time, WHY does this work and not the other?
the headers if you want it to work like on your code, you need to change the header like o. postman
1

You could try stringifying the data. JSON.stringify(data)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.