【发布时间】:2020-05-18 11:32:27
【问题描述】:
我想在控制台打印从 api 获取的数据
我的 php 文件代码是 <?php
echo "Hello";
?>
我的 javascript 文件代码是
function cities(str){
alert(str);
let url = "cities.php";
fetch(url).then( (response)=>{return response; }).then((data)=>{console.log(data);});
}
我正在使用 HTML 文件中的 onclick 属性调用此函数,我想在我的控制台上看到 Hello,但它给我的输出为 like this,当我更改我的 javascript 文件代码时,如
function cities(str){
alert(str);
let url = "cities.php";
fetch(url).then( (response)=>{return response.text(); }).then((data)=>{console.log(data);});
}
然后在控制台中将输出作为php文件see here的完整代码
【问题讨论】:
-
我的回答对你有帮助吗?
标签: javascript php fetch fetch-api