Javascript 无法将符号值转换为字符串删除请求
我不明白为什么在控制台中抛出Javascript 无法将符号值转换为字符串删除请求,javascript,jquery,ajax,reactjs,Javascript,Jquery,Ajax,Reactjs,我不明白为什么在控制台中抛出无法将符号值转换为字符串。我使用的是React v15和jQuery v3 这是我的代码: var CommentList = React.createClass({ handleDelete: function(comment) { console.log(comment); $.ajax({ url: this.props.url, dataType: 'json', type: 'DELETE',
无法将符号值转换为字符串。我使用的是React v15和jQuery v3
这是我的代码:
var CommentList = React.createClass({
handleDelete: function(comment) {
console.log(comment);
$.ajax({
url: this.props.url,
dataType: 'json',
type: 'DELETE',
data: comment,
contentType:'application/json',
dataType: 'text',
success: function(data) {
this.setState({ data: data });
}.bind(this),
error: function(xhr, status, err) {
this.setState({data: comments});
console.error(this.props.url, status, err.toString());
}.bind(this)
})
},
render: function() {
var commentNodes = this.props.data.map(comment => {
return(
<div key= { comment.id }>
<Comment author = { comment.author }>
{ comment.text }
</Comment>
<button onClick={this.handleDelete}>delete</button>
</div>
);
});
return (
<div className="commentList">
{commentNodes}
</div>
);
}
});
您没有将注释传递给handleDelete,它实际上接收的是click事件。您可能不需要使用注释id。请在列表呈现程序中尝试以下操作:
<div key= {comment.id}>
<Comment author ={comment.author}>
{comment.text}
</Comment>
<button onClick={this.handleDelete.bind(this, comment)}>delete</button>
</div>
{comment.text}
删除
您没有将注释传递给handleDelete,它实际上接收的是单击事件。您可能不需要使用注释id。请在列表呈现程序中尝试以下操作:
<div key= {comment.id}>
<Comment author ={comment.author}>
{comment.text}
</Comment>
<button onClick={this.handleDelete.bind(this, comment)}>delete</button>
</div>
{comment.text}
删除
回调的err
变量中有什么?回调的err
变量中有什么?谢谢,你是对的,它没有传递实际的注释。我已经更新了我的代码,它传递了正确的信息,但是现在它在ajax调用中抛出了未定义的“错误”“错误请求”
。这意味着this.props.url
未定义,根据您的代码,这将解释错误请求。谢谢,您是正确的,它没有传递实际的注释。我已经更新了我的代码,它正在传递正确的信息,但现在它在ajax调用中抛出了未定义的“错误”“错误请求”
。这意味着this.props.url
未定义,根据您的代码,这将解释错误请求。