我正在尝试从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;
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句