Axios GET from local PHP just returns code instead of executing

瘦欲@ 提交于 2019-12-12 05:16:54

问题


The API I am trying to access has disabled CORS so I need to request on the server side. Utilizing React and Axios I am making a get request to the local php file which should execute cURL but am just getting the php code back instead of it executing

<?php $curl = curl_init();

curl_setopt($curl, CURLOPT_URL, "https://api.darksky.net/forecast/myAPIKet/coords");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);

curl_close($curl)

echo $result;
return;
?>

<script>
let info = axios.get('./proxy.php')
    console.log(info.data);
</script>

When this runs just the php code is logged in my console instead of the php script triggering and echoing the data I want.


回答1:


Sounds like your environment hasn't got PHP installed.

Do you have anymore information about it?



来源:https://stackoverflow.com/questions/42719086/axios-get-from-local-php-just-returns-code-instead-of-executing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!