使用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 (将#修改为@)