php api doesnt send any message to react native app
one text
Solution:
You are probably missing parsing response.data
as json
in your react-native code.
Convert the raw data you received to json using JSON.parse(response.data)
.
So you could replace your sendRating
method with this:
function sendRating() {
axios
.post("http://192.168.1.107/restaurant/setRate.php", {
rating: this.state.Default_Rating,
ID: this.state.restId,
})
.then((response) => {
var jsonResponseData = JSON.parse(response.data);
if (jsonResponseData.message == "success") {
alert("امتیاز شما ثبت شد");
} else if (jsonResponseData.message == "failure") {
alert("لطفا بعدا دوباره تلاش کنید");
} else {
alert(jsonResponseData.message);
}
});
}
Note: Make sure that the response is not null and also that the data is a valid json before parsing.
Source