我有这个代码在我的反应应用程序,它没有发布json的身体!已经尝试了所有的解决方案,即使这里的https://github.com/matthew-andrews/isomorphic-fetch/issues/34也不起作用,我可以用jquery做文章,但是我需要使用fetch,有什么想法吗?
fetch('/main/newuser',{
method:'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body:JSON.stringify({username:'test',password:'test'})
}).then((response)=>{
if(response.status >= 200 && response.status < 300){
return response;
}else{
var error = new Error(response.statusText);
error.response = response;
throw error;
}
}).then((response)=>{
return response.json();
}).then((data)=>{
/* Process data */
}).catch((error)=>{
/* Catch Error */
});
发布于 2016-10-11 04:02:01
在尝试了一切可能的方法(如建议的编辑代码,检查浏览器的最新和工作,检查服务器代码,库工作将与GET方法,但仍不工作)我切换回我们的旧和爱JQuery!
https://stackoverflow.com/questions/39974555
复制相似问题