我一直在使用带有 babel、webpack、redux 和 semantic-ui-react 的 mern stack 制作一个 Web 应用程序。
但我得到一个错误说
bundle.js 中的“意外令牌 <”。
仅当我单击表单标记中的按钮发送请求时才会发生此错误。如果我制作没有表单标签的页面,它可以正常工作而没有任何错误。
这是我在 React 中的代码。
handleUpload(title, contents, userId) {
return this.props.createPostRequest(title, contents, userId).then(
() => {
if(this.props.post.status === 'SUCCESS') {
alert('Your post is saved successfully.');
browserHistory.push('/');
return true;
} else {
alert('Save Fail: ' + this.props.post.failReason);
return false;
}
}
);
}
render() {
return(
<div className="Write">
<br/>
<br/>
<Form>
<Container text>
<Form.Input label='Title' fluid name='title' placeholder='title'
value={this.state.title} onChange={this.handleChange}>
<input/>
</Form.Input>
<Form.TextArea rows='20' name='contents' placeholder='Write here!'
value={this.state.contents} onChange={this.handleChange}>
<textarea/>
</Form.TextArea>
<br/>
<Button.Group>
<Button color='orange' as={Link} to='/'>Cancel</Button>
<Button.Or/>
<Button positive onClick={this.handleUpload}>Save</Button>
</Button.Group>
</Container>
</Form>
</div>
);
}
当我输入字母并单击保存按钮时,我会看到一条警告消息说
您的帖子已成功保存..
而且我放的数据也保存在mongodb中。但是在我点击确定后,url 会从'localhost:3000/post/write
' 变为 ' localhost:3000/post/write?title=blah&contents=blah
'。url中的blah是我在输入标签中输入的内容。然后控制台说
意外的令牌 <。
但是,如果我不在上面的代码中使用表单标签,它工作正常,我完全不知道有什么问题。表单标签来自语义 UI 反应。所以我需要它。如果我不使用 Form,它可以正常工作,但我应该放弃语义 UI 提供的设计。
有没有人知道这件事?我猜这与表单标签中的 HTTP POST 有关,这使 react.js 在服务器端处理来自该表单标签的发布请求后难以理解 index.html 中的 bundle.js。