我只是想在请求引起CORS headers
的missing headers
问题的出路,因此倾向于使用JSONP
。
任何建议/想法如何在JSONP
应用程序中使用react-redux
?怎么样配置和使用呢?
我在使用最多的应用程序反应病例fetch:
// payload is your post data
const payload = {data: 'test'};
const options = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
cors: true, // allow cross-origin HTTP request
credentials: 'same-origin' // This is similar to XHR’s withCredentials flag
};
// SEND REQUEST
fetch('http://example.com/', options).then((response) => {
// TODO
}).catch((error) => {
// TODO
});
在你的反应组件,派遣由中间件抓的动作。中间件应该给JSONP端点的呼叫,可能使用jQuery的$就法。我也很喜欢fetchJsonp库。然后,您应该中间件与派遣由AJAX或fetchJsonp接收到的数据,这应该由你的减速被抓住了新的动作,并改变状态。