dataType was unnecessary; mimeType was both unnecessary and wrong in this case. Also removed an unnecessary bind and changed pollInterval to 2000 ms for consistency with https://github.com/petehunt/react-tutorial (faster is nicer if you actually try it out!).
All we have done here is move the AJAX call to a separate method and call it when the component is first loaded and every 5 seconds after that. Try running this in your browser and changing the `comments.json` file; within 5 seconds, the changes will show!
All we have done here is move the AJAX call to a separate method and call it when the component is first loaded and every 2 seconds after that. Try running this in your browser and changing the `comments.json` file; within 2 seconds, the changes will show!
### Adding new comments
### Adding new comments
@ -456,7 +449,7 @@ var CommentForm = React.createClass({
<formclassName="commentForm">
<formclassName="commentForm">
<inputtype="text"placeholder="Your name"/>
<inputtype="text"placeholder="Your name"/>
<inputtype="text"placeholder="Say something..."/>
<inputtype="text"placeholder="Say something..."/>
<inputtype="submit"/>
<inputtype="submit"value="Post"/>
</form>
</form>
);
);
}
}
@ -488,7 +481,7 @@ var CommentForm = React.createClass({
placeholder="Say something..."
placeholder="Say something..."
ref="text"
ref="text"
/>
/>
<inputtype="submit"/>
<inputtype="submit"value="Post"/>
</form>
</form>
);
);
}
}
@ -517,8 +510,6 @@ var CommentBox = React.createClass({
loadCommentsFromServer: function() {
loadCommentsFromServer: function() {
$.ajax({
$.ajax({
url: this.props.url,
url: this.props.url,
dataType: 'json',
mimeType: 'textPlain',
success: function(data) {
success: function(data) {
this.setState({data: data});
this.setState({data: data});
}.bind(this)
}.bind(this)
@ -532,10 +523,7 @@ var CommentBox = React.createClass({