reactJSでajax通信を使った処理を作成しています。
ajaxの返り値を見ると、2回実行されているのですが、
これは仕様でしょうか?
調べても有益な情報が得られず…
教えていただけると助かります。
(SuperAgentでもテストしましたが同じく2回実行されていました)
react
1var Compornent = React.createClass({ 2 getInitialState: function(){ 3 return { data: [] }; 4 }, 5 loadCommentsFromServer: function(){ 6 $.ajax({ 7 url: this.props.url, 8 dataType: 'json', 9 cache: 'false', 10 success: function(data){ 11 this.setState({ data: data }); 12 }.bind(this), 13 error: function(xhr, status, err){ 14 console.error(this.props.url, status, err.toString()); 15 }.bind(this) 16 }); 17 }, 18 componentDidMount: function(){ 19 this.loadCommentsFromServer(); 20 }, 21 render: function(){ 22 return ({this.state.data); 23 } 24}); 25ReactDOM.render( 26 <Compornent url="/hoge.json" />, 27 document.getElementById('content') 28);
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/27 05:32
2017/10/27 06:07
2017/10/27 06:16
2017/10/27 06:22
2017/10/27 07:09
2017/10/27 07:11