阵营componentDidMount没有触发jQuery的AJAX调用
问题描述:
我有以下代码:阵营componentDidMount没有触发jQuery的AJAX调用
import React from 'react';
import {render} from 'react-dom';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data: ''
};
}
componentDidMount() {
$.get(this.props.source, function(result) {
this.setState({data: result});
}.bind(this));
}
render() {
return (
<div>
<p>{this.state.data}</p>
</div>
)
}
}
render(<App source='https://s3-eu-west-1.amazonaws.com/streetlife-coding-challenge/newsfeed.json'/>, document.getElementById('app'));
的package.json:
{
"name": "streetlife",
"version": "1.0.0",
"description": "technical test for streetlife",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.16.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"webpack": "^1.13.2"
}
}
我期望在我的 “P” 标签提供的JSON数据但屏幕是空的,我也没有得到错误。
我在环境中没有得到任何错误... – Alex
您认为什么样的环境问题? – Alex
解决了,我在脚本标记中加载了jQuery。我删除了这个,并且在上面的jsx文件中导入了它。谢谢 – Alex