SetState problem in reachjsajax

  node.js, question

clipboard.png

clipboard.png

The data of an object acquired through ajax and passed to the state is first converted into string and then into object, but an error is reported when it is converted. If only one string is passed directly to data in ajax inside

See you this code is using ES2015 syntax, can directly use arrow function to avoidthisThe problem, such as:

var Home = React.createClass({
 //   ......
 getData() {
 $.ajax({
 //   ....
 success: data => {
 //   ....
 this.setState(/* ... */);
 bracket
 });
 bracket
 });

However, the syntax of ES6 is not well supported by all browsers. If you use ES5 syntax, you can declare one_thisVariable temporary storagethisFor example

var Home = React.createClass({
 //   ......
 getData: function() {
 var _this = this;
 $.ajax({
 //   ....
 success: function(data) {
 //   ....
 _this.setState(/* ... */);
 bracket
 });
 bracket
 });