I have a Web API that takes 3 parameters (e.g: int EID, string MUN, string MUP) and then return a JSON like this:
[
{
"MemberID": 71,
"MemberExamID": 1
}
]
Now I want to alert 'MemberID' in my React-JS project, when the user click on 'Submit' button. and this is part of my React-JS codes too:
export class LoginModal extends Component {
constructor(props) {
super(props);
this.state = { MemberID: 0}
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(event) {
event.preventDefault();
fetch(process.env.REACT_APP_API + 'MemberExamValidation', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
EID: event.target.ExamID.value,
MUN: event.target.EDT_Username.value,
MUP: event.target.EDT_Password.value
})
})
.then(res => res.json())
.then(data => {
this.setState({ MemberID: data.MemberID });
alert(this.state.MemberID);
},
(error) => {
alert('Erroe');
})
}