Ich habe einfach jsonReactJs machen einfach JSON
{"id":157,"content":"Hello, World!"}
I id in einem div und Inhalt in anotther machen möchten. Problem für mich ist, wenn ich {this.state.data.content}
zweimal anrufe, stürzt es ab.
var Stuff = React.createClass({
getInitialState: function() {
return {
data: []
};
},
componentDidMount: function() {
$.ajax({
url: "http://rest-service.guides.spring.io/greeting",
dataType: 'json',
cache: false,
success: function(response) {
this.setState({
data: response
});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
render: function() {
return (
<div>Response - {this.state.data.content}</div>
);
}
});
Haben Sie [Ihre Konsole überprüft] (http://stackoverflow.com/documentation/javascript/185/hello-world/714/using-console-log) auf Fehler überprüft? –
Ich weiß nicht, wovon du redest – TeodorKolev