ich den folgenden Code haben redux-Saga durch die Verwendung eines Post-Anforderung zu senden:Fetch Post funktioniert nicht in Redux-Saga?
import {put, call, fork, takeEvery} from 'redux-saga/effects';
import fetch from 'isomorphic-fetch';
const url = 'xxx/api/posts';
function* addPost(data) {
try{
const response = yield fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json, application/xml, text/plain, text/html, *.*',
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify(data)
});
const id = yield response.json().id;
yield put({type: types.ADD_POST, payload: {id, title, content }});
}catch(e) {
yield put({type: types.ERROR, payload: e});
}
}
Aber ein Ajax mit dem OPTION-Methode gesendet, was mit meinem Code falsch? Warum es nicht funktioniert?