【发布时间】:2020-10-07 22:26:46
【问题描述】:
我正在研究 React 并使用 Spring Boot 制作的 POST API。 这是代码
async postData() {
console.log(JSON.stringify(this.state));
try {
const results = await fetch("/student", {
crossDomain: true,
method: "POST",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify(this.state),
});
const data = await results.json();
console.log("data", data);
//this.props.history.push("/Resume");
this.setState({
owner: "",
student_field_interest1: "",
student_field_interest2: "",
firstname: "",
lastname: "",
contactno: 0,
address: "",
gender: "",
});
} catch (err) {
console.log(err);
}
}
在访问 API 之前 我正在发送这个 JSON 对象
{"data":[],"owner":"5eeaac70f21e4c2b3a35a8c0","student_field_interest1":"ML","student_field_interest2":"DL","firstname":"Pushkar","lastname":"Jain","contactno":"09991736000","address":"Room no 106 Oxford Caps Upes Road","gender":"Male"}
在击球时 我收到此错误
SyntaxError: JSON 中第 2 位的意外标记 e
【问题讨论】:
-
服务器返回什么?听起来它不是有效的 JSON。
-
你能发布console.log的输出吗?
-
可能是服务器端的错误,有错误可以查看springboot控制台吗?
标签: javascript json reactjs spring-boot post