react post传递数据有问题
代码如下:
var CommentBox = React.createClass({
loadCommentsFromServer: function(){
$.ajax({
url: this.props.url,
dataType: 'json',
success: function(data){
this.setState({data: data});
}.bind(this),
error: function(xhr,status,err){
console.log(this.props.url,status,err.toString());
}.bind(this)
});
},
handleCommentSubmit: function(comment){
var comments = this.state.data;
var newComments = comments.concat([comment]);
this.setState({data: newComments});
$.ajax({
url: this.props.url,
dataType: 'json',
type: 'POST',
data: comment,
success: function(data){
this.setState({data: data});
}.bind(this),
error: function(xhr,status,err){
console.error(this.props.url,status,err.toString());
}.bind(this)
});
},
getInitialState: function(){
return {data: []};
},
GET方法获取数据没有问题,但POST方法提交数据总是报comments.json not found 404错误。