【发布时间】:2018-09-02 19:09:51
【问题描述】:
我想检索function(response) 之外的变量值。我能怎么做?请帮忙!
<script>
Test();
function Test(){
var c = "";
filter();
function filter(data) {
c = data;
console.log(data);
}
var url = 'https://www.json-generator.com/api/json/get/coyqwdNpWq?indent=2';
fetch(url, {
method: 'GET',
})
.then(function(response){
return response.json();
})
.catch(function(error){
console.error('Error:', error);
})
.then(function(response){
//console.log('Success:', response[0].name);
filter(response[0].name);
});
}
</script>
我的结果是用"dara@" 找到但undefined 是这样的:
undefined
"dara@"
【问题讨论】:
-
好吧 .... 函数测试没有返回任何东西 - 即
undefined
标签: javascript promise fetch fetch-api