如何解决使用React native,来自localhost数据库的记录显示在Web浏览器中,而不显示在android智能手机中我正在使用博览会
error i am getting is shown in this picture
javascript文件show.js
import React,{ Component } from 'react'
import { View,Text,FlatList } from 'react-native'
export class Show extends Component {
state = {
data: ''
}
componentDidMount = () => {
fetch('http://192.168.43.119/native/show_user_info.PHP',{
method: 'GET'
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
this.setState({
data: responseJson
})
})
.catch((error) => {
console.error(error);
});
}
render() {
return (
<View>
<FlatList
data={this.state.data}
renderItem={({item})=>(
<Text key={item.id}>{item.uname}</Text>
)}
/>
</View>
)
}
}
export default Show
我尝试在上述javascript代码中提取https://jsonplaceholder.typicode.com/posts,它工作正常,并在android手机和网络上显示输出 (当用 {item.title} 替换 {item.uname} 时) https://jsonplaceholder.typicode.com/posts我从互联网上获得了此链接)
但是当我更改链接并尝试获取本地数据库时,它仅在Web浏览器上显示输出,而在android上不起作用,得到图片中上面显示的错误
PHP文件show_user_info.PHP 它存储在本地服务器Wamp中
// $HostName = "127.0.0.1";
$HostName = "localhost";
//Define your database name here.
$DatabaseName = "arid-chat";
//Define your database username here.
$HostUser = "root";
//Define your database password here.
$HostPass= "";
// Creating connection.
$conn = MysqLi_connect($HostName,$HostUser,$HostPass,$DatabaseName);
if ($conn->connect_error) {
die("Connection Failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM registration";
$result = $conn->query($sql);
if ($result->num_rows >0) {
while($row[] = $result->fetch_assoc()) {
$tem = $row;
$json = json_encode($tem);
}
} else {
echo "No Results Found.";
}
echo $json;
$conn->close();
?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。