我在Spring Boot中设置了我的api,当您调用其中一种方法时,它将返回成功或失败的字符串。但是,我的提取成功了,但是当我尝试将其保存到变量中时,它表示未定义。如何从我的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;
})
我希望您将响应作为json发送。如果是,那么请使用.then((resp)=> resp.json())。请检查以下完整的示例,以使用fetch调用api。