我已经在python上设置了flask服务器,并成功将获取请求发送到了后端。但是,该代码在执行以下代码后返回错误。 LogInClick是调用引发错误的函数的函数。调用该函数后,网页将返回对象promise,woo,然后返回SyntaxError。我正在努力查找导致错误的原因,请您能帮助我吗?
我尝试检查一下括号以确保没有错位,但我无法解决问题。
loginClick() {
let a = this.state.IS.checkExists(this.state.username);
alert(a);
if (a === false) {
alert("Username not found!");
} else if (this.state.IS.checkPassword(this.state.password) === true){
alert("Password incorrect");
} else {
alert("woooo");
this.setState({
loggedIn: true
});
}
if (this.setState.loggedIn) {
window.location.pathname = '/workspacehome';
}
}
async checkExists(user) {
await postData(a.BASE_URL, {'u_n': user}) // THIS IS LINE 10
.then(data => alert(JSON.stringify(data))) // JSON-string from `response.json()` call
.catch(error => {
console.log(error);
alert(error);
});
}
let a = new Configuration();
function postData(url = '', data = {}) { //THIS IS LINE 47
// Default options are marked with *
return fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'no-cors', // no-cors, cors, *same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrer: 'no-referrer', // no-referrer, *client
body: JSON.stringify(data), // body data type must match "Content-Type" header
})
.then(response => response.json()); // parses JSON response into native Javascript objects
}
```javascript
SyntaxError: Unexpected end of input
at item_service.js:47
at async ItemService.checkExists (item_service.js:10)