Skip to content

Commit 1873e1d

Browse files
sophiebitszpao
authored andcommitted
Add dataType to all $.ajax calls for consistency
Fixes https://groups.google.com/forum/#!topic/reactjs/WWA3ZqU6y4w.
1 parent 27ac8a3 commit 1873e1d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

docs/docs/tutorial.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,13 @@ var CommentBox = React.createClass({
410410

411411
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.
412412

413-
```javascript{3,15-16,30}
413+
```javascript{3,16-17,31}
414414
// tutorial14.js
415415
var CommentBox = React.createClass({
416416
loadCommentsFromServer: function() {
417417
$.ajax({
418418
url: this.props.url,
419+
dataType: 'json',
419420
success: function(data) {
420421
this.setState({data: data});
421422
}.bind(this)
@@ -515,12 +516,13 @@ When a user submits a comment, we will need to refresh the list of comments to i
515516

516517
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:
517518

518-
```javascript{11-13,27}
519+
```javascript{12-14,28}
519520
// tutorial17.js
520521
var CommentBox = React.createClass({
521522
loadCommentsFromServer: function() {
522523
$.ajax({
523524
url: this.props.url,
525+
dataType: 'json',
524526
success: function(data) {
525527
this.setState({data: data});
526528
}.bind(this)
@@ -581,12 +583,13 @@ var CommentForm = React.createClass({
581583

582584
Now that the callbacks are in place, all we have to do is submit to the server and refresh the list:
583585

584-
```javascript{12-19}
586+
```javascript{13-21}
585587
// tutorial19.js
586588
var CommentBox = React.createClass({
587589
loadCommentsFromServer: function() {
588590
$.ajax({
589591
url: this.props.url,
592+
dataType: 'json',
590593
success: function(data) {
591594
this.setState({data: data});
592595
}.bind(this)
@@ -595,6 +598,7 @@ var CommentBox = React.createClass({
595598
handleCommentSubmit: function(comment) {
596599
$.ajax({
597600
url: this.props.url,
601+
dataType: 'json',
598602
type: 'POST',
599603
data: comment,
600604
success: function(data) {
@@ -627,12 +631,13 @@ var CommentBox = React.createClass({
627631

628632
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.
629633

630-
```javascript{12-14}
634+
```javascript{13-15}
631635
// tutorial20.js
632636
var CommentBox = React.createClass({
633637
loadCommentsFromServer: function() {
634638
$.ajax({
635639
url: this.props.url,
640+
dataType: 'json',
636641
success: function(data) {
637642
this.setState({data: data});
638643
}.bind(this)
@@ -644,6 +649,7 @@ var CommentBox = React.createClass({
644649
this.setState({data: newComments});
645650
$.ajax({
646651
url: this.props.url,
652+
dataType: 'json',
647653
type: 'POST',
648654
data: comment,
649655
success: function(data) {

0 commit comments

Comments
 (0)