【发布时间】:2015-12-03 04:53:39
【问题描述】:
你好,学习使用 js 和 react-native。我不能使用 FormData 它总是显示不支持的 bodyinit 类型。我想发送文本而不是 JSON.stringify。谁能帮我?谢谢!
var data = new FormData()
data.append('haha', 'input')
fetch('http://www.mywebsite.com/search.php', {
method: 'post',
body: data
})
.then((response) => response.json())
.then((responseData) => {
console.log('Fetch Success==================');
console.log(responseData);
var tempMarker = [];
for (var p in responseData) {
tempMarker.push({
latitude: responseData[p]['lat'],
longitude: responseData[p]['lng']
})
}
this.setState({
marker: tempMarker
});
})
.catch((error) => {
console.warn(error);
})
.done();
【问题讨论】:
-
实际的错误信息是什么?
-
"不支持的 bodyinit 类型"
-
在 react-native
make sure not to have the react-native debugger attached中处理 FormData 时。否则你会有问题。
标签: javascript react-native fetch-api