I tried to pass multiple values to API using JSON.stringfy(). I don't know why my second value is not passing.
This is the code of my attempt:
getUserDetails(email, password){
this.api="http://192.168.1.14/task/public/api/login";
this.http.post(this.api,JSON.stringify(email,password))
.subscribe(data =>
{
if(data !=null)
{
console.log("LoggedIn Sucess");
}
else{
console.log("Login Failed");
}
})
}
The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
JSON.stringify as name suggests convert a JavaScript object into a string representation.
so try this:
getUserDetails(email, password){
this.api="http://192.168.1.14/task/public/api/login";
this.http.post(this.api,JSON.stringify({email: email, password: password}))
.subscribe(data => {
if(data != null) {
console.log("loggedIn success");
} else {
console.log("loggedIn failed");
}
})
}