Axios请求上的内部服务器错误500

问题描述 投票:0回答:2

我有http://localhost:81/log_api.php运行的api,然后我在http://localhost:3000运行的同一台计算机上有React应用程序。以下是React应用的代码:

import React, { Component } from 'react';
import axios from 'axios';

class Logging extends Component {

   state={
       pl_log:[]
     }

     async componentDidMount(){
        await axios.get("http://localhost:81/log_api.php")
         .then(response=>this.setState(
             {
               pl_log: response.data

             } ))

        console.log(this.state)       
     }


   render(){
       return(
           <div>
               Logging
           </div>
       )
   }
  }

  export default Logging;

Console.log显示一些错误:enter image description here

我也直接访问了http://localhost:81/log_api.php,一点问题都没有。它在浏览器上显示JSON数据。仅当我在React中使用axios时,才会出现此问题。

文件名:log_api.php

<?php



$link = mysqli_connect("127.0.0.1:3307", "root", "root", "masterdb");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

$sql = $link -> query("SELECT * FROM pl_log");
$result=array();

while ($data = $sql -> fetch_assoc()){
    $result[]=$data;
}
echo json_encode($result);


mysql_close($link);

?>

网络屏幕截图:enter image description here

javascript reactjs server axios internals
2个回答
0
投票

您可以尝试使用IP地址http://127.0.0.1

希望它对您有用


0
投票

@@ rickdenhaan解决了我的问题!

© www.soinside.com 2019 - 2024. All rights reserved.