【发布时间】:2018-04-26 01:24:06
【问题描述】:
我正在尝试通过 reactjs 中的fetch 发出 POST 请求。我浏览了一些文档,但我的错误没有解决。有人可以帮我吗?
这是我的 reactjs 代码:
handleSubmit(e) {
e.preventDefault();
var self = this;
const payload = {
id: 111,
studentName: 'param',
age: 24,
emailId: 2
};
fetch({
method: 'POST',
url: 'http://localhost:8083/students',
body: payload,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then(function(response) {
return response.json()
}).then(function(body) {
console.log(body);
});
}
}
如果有熟悉reactjs的人,请举一个简单的例子,如何调用post request。使用fetch或axios。
【问题讨论】:
-
您能否编辑问题,代码丢失?
-
@niklaz 感谢您的回复,已添加代码
标签: javascript json reactjs fetch