0
我有這個代碼在我的反應的應用程序,它沒有發佈json的身體! 已經嘗試了每個解決方案,即使這裏的一個https://github.com/matthew-andrews/isomorphic-fetch/issues/34也不能工作,我可以用jquery做這個帖子,但是我需要使用fetch,任何想法?isomorophic-fetch不發佈json主體
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 */
});
什麼是服務器的響應? – Shota
在僞造的API上使用您的代碼時,它可以正常工作。我無法重現該問題。你確定你的API工作正常嗎? http://jsbin.com/foyanir/edit?js,console –
服務器無法獲得json正文,使用jquery時效果很好,所以服務器代碼沒問題, –