【发布时间】:2022-01-21 00:31:18
【问题描述】:
我试图从 PHPMyAdmin 获取请求数据,然后将其输出到我的 react 本机项目中,我使用 response.data.username,但我得到了未定义。
const getInfo = () => {
axios.get("https://luxrealest.com/includes/user_registration.php").then(
(response) => {
console.log(response.username);
setDataInfo(response.data.username + " " + response.data.email);
})
}
getInfo()
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.24.0/axios.min.js" integrity="sha512-u9akINsQsAkG9xjc1cnGF4zw5TFDwkxuc9vUp5dltDWYCSmyd0meygbvgXrlc/z7/o4a19Fb5V0OUE58J7dcyw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
预期
Object {
"": Object {
"email": "myke@myke.com",
"id": "11",
"username": "myke",
},
"1": Object {
"email": "aisosa.erharuyi11@gmail.com",
"id": "12",
"username": "General.Bigman",
},
"2": Object {
"email": "amiatorjay@gmail.com",
"id": "13",
"username": "Jaycee",
},
}
【问题讨论】:
-
我试图让你成为minimal reproducible example - 当我将 Axios 小写时出现 CORS 错误
-
@mplungjan,使用 Postman 我能够从该 URL 获得响应。在浏览器中,我也收到 CORS 错误。
-
Postman 不会给出 CORS 错误。您尝试访问的端点需要实现Access control allow origin
标签: javascript php reactjs react-native axios