@@ -32,17 +32,15 @@ var Comment = React.createClass({
3232} ) ;
3333
3434var CommentBox = React . createClass ( {
35+ logError : function ( xhr , status , err ) {
36+ console . error ( `Error loading comments from server!\nURL is ${ this . props . url } \nstatus is ${ status } \nerr is ${ err . toString ( ) } ` ) ;
37+ } ,
3538 loadCommentsFromServer : function ( ) {
3639 $ . ajax ( {
3740 url : this . props . url ,
38- dataType : 'json' ,
39- success : data => {
41+ dataType : 'json' } ) . then ( data => {
4042 this . setState ( { data : data } ) ;
41- } ,
42- error : ( xhr , status , err ) => {
43- console . error ( this . props . url , status , err . toString ( ) ) ;
44- }
45- } ) ;
43+ } , this . logError ) ;
4644 } ,
4745 emptyFormData : { author : "" , text : "" } ,
4846 handleCommentSubmit : function ( ) {
@@ -55,17 +53,14 @@ var CommentBox = React.createClass({
5553 url : this . props . url ,
5654 dataType : 'json' ,
5755 type : 'POST' ,
58- data : { comment : comment } ,
59- success : data => {
56+ data : { comment : comment } } ) . then ( data => {
6057 var comments = this . state . data ;
6158 var newComments = React . addons . update ( comments , { $push : [ comment ] } ) ;
6259 this . setState ( { ajaxSending : false , data : newComments , formData : this . emptyFormData } ) ;
63- } ,
64- error : ( xhr , status , err ) => {
65- console . error ( this . props . url , status , err . toString ( ) ) ;
60+ } , ( xhr , status , err ) => {
61+ this . logError ( xhr , status , err ) ;
6662 this . setState ( { ajaxSending : false } ) ;
67- }
68- } ) ;
63+ } ) ;
6964 } ,
7065 getInitialState : function ( ) {
7166 return {
0 commit comments