I have a function in php, that returns the json_encoded
version of a string, but when I console.log
the response gotten from the json_encoded data in my react app, through axios, the data is usually empty,usually like this,Object {data: "", status: 200, statusText: "OK", headers: Object, config: Object…}
,Please what may be the issue
PHP FILE
header("Access-Control-Allow-Origin: *");
return json_encode("works");
React file
import axios from 'axios';
class LoginComponent extends Component {
componentDidMount() {
axios.get('http://localhost/login.php')
.then(response => {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
}