2

I'm using fetch to send value to my server. my server is php. when I send my values with postman my server response as well.

but when I want to send my values with fetch I cannot get them from server side.

postman: enter image description here

my requestOption:

  const requestOptions = {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },

            body: JSON.stringify(parms)
        };

my values sent to server but I cannot get them like postman form-data.

parms is a object variable. like:

var parms = {};
parms['tok'] = '35345345';
1
  • 1
    you dont need to json stringify them i tihink Commented Nov 8, 2018 at 14:00

1 Answer 1

3

Just use formData as fetch body:

var formData = new FormData()
formData.append("tok", '35345345')
const requestOptions = {
        method: 'POST',
        headers: {
            'Accept': 'application/json'
        },

        body: formData
    };
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.