React + Flux, ES6, Babel ActionCreate使用json-server和超级代理,数据不响
React + Flux, ES6, Babel ActionCreate using json-server and super agent, data not in response
你好,我正在尝试使用json-server来模拟我正在构建的React Flux ES6应用程序的api。但当我使用超级代理节点模块向操作创建者发出请求时回调中的数据是undefined
这是我的代码
import Dispatcher from '../Dispatcher';
import Constants from '../Constants';
import request from 'superagent';
export default {
setQuestions(guides) {
Dispatcher.handleViewAction({
type: Constants.ActionTypes.SET_QUESTIONS,
data: guides
});
},
getQuestionsFromServer() {
let self = this;
let destination = 'http://localhost:3000/questionnaires';
// request from json service.
request
.get(destination)
.set({
'X-Requested-With': 'XMLHttpRequest'
})
.end(function(response) {
// response is empty. why???
if (response.ok) {
let guideData;
guideData = response.body;
self.setQuestions(guideData);
}
});
}
};
我的网络选项卡说请求发生了,但我无法访问回调中的响应。
我弄清楚了如何通过使用fetch es2015使这个xhr请求没有超级代理节点模块。在这里看到的:https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch
getQuestionsFromServer() {
let self = this;
let destination = 'http://localhost:3000/questionnaires';
// request from json service.response.json()
fetch(destination)
.then(response => response.json())
.then(data => {
this.setQuestions(data[0].questions);
})
.catch(e => console.log("Error", e));
}
谢谢!
相关文章:
- 用程序搜索JQuery数据表中的文本
- 要求输入在数据列表中
- 正在将数据主题添加到所有项目
- 函数参数中的数据与指定变量之间的任何性能差异
- 在VanillaJS中模拟模型双向数据绑定
- CSS-如何定位内容数据标题
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 序列化数据属性中对象的最可靠方法
- 如何将JSON数据导入我的ejs模板
- 将 json 数据存储在代理模式内的变量中
- 通过代理服务器从Javascript调用数据
- extjsJsonP代理可以't加载大量数据
- 错误'无效数据'同时使用node-v0.10.4作为websocket代理
- 如何覆盖Sencha Touch数据存储代理异常侦听器
- 将数据绑定到ExtJS中存储的rest代理中查看
- Extjs数据模型/存储是否支持任何包装代理构建器方法?
- Chrome数据压缩代理错误与jquery ajax表单提交
- React + Flux, ES6, Babel ActionCreate使用json-server和超级代理,数据不响
- 进程 extjs 在收到数据后存储代理数据