【发布时间】:2020-05-18 07:34:31
【问题描述】:
我在 Spring Boot 中设置了我的 api,当您调用其中一个方法时,它会返回一个成功或失败的字符串。但是,我的 fetch 控制台成功,但是当我尝试将其保存到变量时,它显示未定义。如何从我的 api 获取成功或失败字符串?
handleSubmit(event) {
var a ;
event.preventDefault();
this.setState({username:'poop'})
console.log("submit");
fetch('http://localhost:8080/login/'+this.state.username+'/'+this.state.password,{
method: 'GET',
}).then((resp)=> resp.text())
.then(function(data){
a= data;
})
【问题讨论】:
标签: javascript reactjs api fetch