0
私の反応アプリにこのコードがあり、jsonボディを投稿しませんでした! ここでもすべての解決方法を試してみたhttps://github.com/matthew-andrews/isomorphic-fetch/issues/34 jqueryで投稿を行うことはできますが、フェッチを使用する必要がありますか?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を使用すると正常に動作するため、サーバーコードはOKです。 –