![](/img/trans.png)
[英]Chrome Browser debugger comes back with jQuery statements as being “undefined functions”
[英]'fetch' call comes back as undefined?
我目前正在开发一个从php后端检索数据的react-native应用程序,当我调用以下函数时,我的编译器会不断返回“'fetch'is def”信息。有人知道为什么我可能会遇到一些错误?
onButtonPress = () => { fetch('http://www.fitnessinspirationtechnologies.com/ReactNative/login_RN.php', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
response: 'response',
id: 'id',
type: 'type'
})
})
.then((response) => response.json())
.then((res) => {
console.log(res.response, res.id, res.type);
})
.done();
}
提取仅是前端的,在某些浏览器中尚不支持。 我猜你的反应本机环境尚不支持fetch
。
您可以考虑为其添加一个polyfill,从而为您提供服务器端版本并为那些浏览器创建此功能。
$ npm install --save unfetch
然后将其导入您的项目:
使用ES6 import fetch from 'unfetch'
使用CommonJS模块的var fetch = require('unfetch')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.