【发布时间】:2017-08-27 19:19:24
【问题描述】:
我有以下代码通过使用 redux-saga 发送一个 post 请求:
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});
}
}
但是使用 'OPTION' 方法发送了一个 ajax,我的代码有什么问题?为什么它不起作用?
【问题讨论】:
标签: reactjs redux cors fetch-api redux-saga