J
J
Jasulan982018-05-10 10:29:57
JavaScript
Jasulan98, 2018-05-10 10:29:57

How to send json to server in react native?

Everyone is talking only about how to get json? How to send data to the site (Web API)? What function in javascript does fetch seem to accept? (do not judge strictly the first time I write Javascript)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TerNik, 2018-05-10
@TerNik

var data = {
   "username": this.state.username,
   "password": this.state.password
}

fetch("https://....", {
   method: "POST",
   headers: headers,
   body:  JSON.stringify(data)
})
.then(function(response){ 
 return response.json();   
})
.then(function(data){ 
console.log(data)
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question