Home responseData gives an error ReactNative
Reply: 2

responseData gives an error ReactNative

Saddaf Afrin
1#
Saddaf Afrin Published in 2017-12-07 06:53:49Z
fetch(loginApi, {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    Password: password,
    UserName: username
  })
})
  .then(response => response.json())
  .then(responseData => {
    console.log(responseData); //// <--- getting error at this line
  })
  .catch(error => {
    console.error(error);
  });

enter image description here

Any idea how to solve it??? Thanks in advance.

Jigar
2#
Jigar Reply to 2017-12-07 07:46:27Z

maybe response data is not in json format try this

fetch(loginApi, {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    Password: password,
    UserName: username
  })
}).then((e)=>{
 console.log(e) //see what you get, if promise then use another then 
})
Codelady Afrin
3#
Codelady Afrin Reply to 2017-12-08 19:28:38Z

Luckily I have found the solution.

var loginParams = {
        Password: password,
        UserName: username
    };

    var loginFormData = new FormData();

    for (var param in loginParams) {
        loginFormData.append(param, loginParams[param]);
    }

    fetch(loginApi, {
     method: "POST",
      headers: { /// <---- you can remove this headers if you are not using any headers in postman..
    Accept: "application/json",
    "Content-Type": "application/json"
  },
  body: loginFormData
})
  .then(response => response.json())
  .then(responseData => {
    console.log(responseData); //// <--- getting error at this line
  })
  .catch(error => {
    console.error(error);
  });

for more information please check this enter link description here

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313683 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO