Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions scripts/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ var Comment = React.createClass({

var CommentBox = React.createClass({
loadCommentsFromServer: function() {
$.ajax({
url: this.props.url,
dataType: 'json',
success: function(data) {
$.getJSON(this.props.url)
.done($.proxy(function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
}, this))
.fail($.proxy(function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
}, this))
.always($.proxy(function() {
setTimeout(this.loadCommentsFromServer, this.props.pollInterval);
}, this))
;
},
handleCommentSubmit: function(comment) {
var comments = this.state.data;
Expand All @@ -36,26 +37,18 @@ var CommentBox = React.createClass({
// `setState` accepts a callback. To avoid (improbable) race condition,
// `we'll send the ajax request right after we optimistically set the new
// `state.
$.ajax({
url: this.props.url,
dataType: 'json',
type: 'POST',
data: comment,
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
$.post(this.props.url, comment)
.fail($.proxy(function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
}, this))
;
});
},
getInitialState: function() {
return {data: []};
},
componentDidMount: function() {
this.loadCommentsFromServer();
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
},
render: function() {
return (
Expand Down