@samitouri / QOS-React-2 / commits / eb2ac7f2f2

Add dataType to all $.ajax calls for consistency

Fixes https://groups.google.com/forum/#!topic/reactjs/WWA3ZqU6y4w.

Ben Alpert committed Jan 13, 2014 at 19:54 UTC eb2ac7f2f2588dcae64e0ab6c4a70adf9d427748
1 file changed +10 -4
docs/docs/tutorial.md
+10 -4
@@ -410,12 +410,13 @@ var CommentBox = React.createClass({
410
411 Here, `componentWillMount` is a method called automatically by React before a component is rendered. The key to dynamic updates is the call to `this.setState()`. We replace the old array of comments with the new one from the server and the UI automatically updates itself. Because of this reactivity, it is trivial to add live updates. We will use simple polling here but you could easily use WebSockets or other technologies.
412
413 -```javascript{3,15-16,30}
413 +```javascript{3,16-17,31}
414 // tutorial14.js
415 var CommentBox = React.createClass({
416 loadCommentsFromServer: function() {
417 $.ajax({
418 url: this.props.url,
419 + dataType: 'json',
420 success: function(data) {
421 this.setState({data: data});
422 }.bind(this)
@@ -515,12 +516,13 @@ When a user submits a comment, we will need to refresh the list of comments to i
516
517 We need to pass data from the child component to its parent. We do this by passing a `callback` in props from parent to child:
518
518 -```javascript{11-13,27}
519 +```javascript{12-14,28}
520 // tutorial17.js
521 var CommentBox = React.createClass({
522 loadCommentsFromServer: function() {
523 $.ajax({
524 url: this.props.url,
525 + dataType: 'json',
526 success: function(data) {
527 this.setState({data: data});
528 }.bind(this)
@@ -581,12 +583,13 @@ var CommentForm = React.createClass({
583
584 Now that the callbacks are in place, all we have to do is submit to the server and refresh the list:
585
584 -```javascript{12-19}
586 +```javascript{13-21}
587 // tutorial19.js
588 var CommentBox = React.createClass({
589 loadCommentsFromServer: function() {
590 $.ajax({
591 url: this.props.url,
592 + dataType: 'json',
593 success: function(data) {
594 this.setState({data: data});
595 }.bind(this)
@@ -595,6 +598,7 @@ var CommentBox = React.createClass({
598 handleCommentSubmit: function(comment) {
599 $.ajax({
600 url: this.props.url,
601 + dataType: 'json',
602 type: 'POST',
603 data: comment,
604 success: function(data) {
@@ -627,12 +631,13 @@ var CommentBox = React.createClass({
631
632 Our application is now feature complete but it feels slow to have to wait for the request to complete before your comment appears in the list. We can optimistically add this comment to the list to make the app feel faster.
633
630 -```javascript{12-14}
634 +```javascript{13-15}
635 // tutorial20.js
636 var CommentBox = React.createClass({
637 loadCommentsFromServer: function() {
638 $.ajax({
639 url: this.props.url,
640 + dataType: 'json',
641 success: function(data) {
642 this.setState({data: data});
643 }.bind(this)
@@ -644,6 +649,7 @@ var CommentBox = React.createClass({
649 this.setState({data: newComments});
650 $.ajax({
651 url: this.props.url,
652 + dataType: 'json',
653 type: 'POST',
654 data: comment,
655 success: function(data) {