0

I have a multi select input. If ı select any option and send not problem. When not select any value. then send form with empty array. But formData not accept to [].

let formData = new FormData();
formData.append('education_level', []); //not accept
1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Feb 16, 2022 at 6:52

2 Answers 2

2

The append method only accepts strings or Blob objects (including File objects).

FormData is for use when you're going to provide multipart/form-data. There's no concept of an empty array in multipart/form-data, you just don't include any values for the key at all, and the server should infer that that means any "array" of values it was expecting is empty.

For completeness: If you did have an array of values, you wouldn't do .append("theKey", theArray); instead, you'd append them like this:

for (const value of theArray) {
    data.append("theKey", value);
}

All of the values will be included in the result.

Sign up to request clarification or add additional context in comments.

Comments

-1
formData.append('education_level',`${[]}`);

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.