我正在尝试从 php 文件中获取值
API.php
<?php
// want to fetch this value
$a = 'come!! fetch this value';
?>
我的 javascript 页面有这样的代码。(此代码不在页面 api.php 上)
fetch('http://localhost/react_task/react-webpack-boilerplate/php/api.php', {
method: 'get',
// may be some code of fetching comes here
}).then(function(response) {
if (response.status >= 200 && response.status < 300) {
return response.text()
}
throw new Error(response.statusText)
})
.then(function(response) {
console.log(response);
})
你能指导我如何使用 fetch 从 php 文件中获取变量的值吗?
最佳答案
你没有回应这个值,所以它不会被发送。
<?php
// want to fetch this value
$a = 'come!! fetch this value';
echo $a;
?>
关于javascript - 从 php 文件中获取 api (GET DATA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39414008/