reactjs入门到实战(九)----ajax的应用
利用外部的jquery:
<script type="text/babel"> var Count = React.createClass({ getInitialState:function(){ return{ count:0 } }, componentDidMount:function(){ this.timer =setInterval(function(){ $.get('http://ip/apishow/pv.php',function(data){ var obj = eval('(' + data + ')'); this.setState({count:obj[0]['value']}); }.bind(this)) }.bind(this),1000) }, render:function(){ return ( <div> <a>PV: {this.state.count} </a> </div> ); } }); ReactDOM.render( <Count />, document.getElementById('example') ) </script>