TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
selvi jp
NA
323
77.8k
Unhandled Rejection (SyntaxError): Unexpected end of input
May 30 2021 2:25 AM
import
React, { Component } from
'react'
;
import
{ Button, Card, CardBody, CardGroup, Col, Container, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row } from
'reactstrap'
;
class
ApiLogin
extends
Component {
constructor() {
super
();
this
.state = {
username:
''
,
Password:
''
}
this
.Password =
this
.Password.bind(
this
);
this
.username =
this
.username.bind(
this
);
this
.login =
this
.login.bind(
this
);
}
username(event) {
this
.setState({ username: event.target.value })
}
Password(event) {
this
.setState({ Password: event.target.value })
}
login(event) {
window.fetch(
'http://*******'
, {
method:
'post'
,
mode:
'no-cors'
,
headers: {
'Access-Control-Allow-Origin'
:
'http:******'
},
body: JSON.stringify({
username:
this
.state.username,
Password:
this
.state.Password
})
}).then((Response) => Response.json())
.then((result) => {
console.log(result);
if
(result.Status ==
'Invalid'
)
alert(
'Invalid User'
);
else
this
.props.history.push(
"/Dashboard"
);
})
}
render() {
return
(
<div className=
"app flex-row align-items-center"
>
<Container>
<Row className=
"justify-content-center"
>
<Col md=
""
lg=
""
xl=
""
>
<CardGroup>
<Card className=
"p-"
>
<CardBody>
<Form>
<div className=
"mb- pageheading"
>
<div className=
"col-sm- btn btn-primary"
>
Login
</div>
</div>
<InputGroup className=
"mb-"
>
<Input type=
"text"
onChange={
this
.username} placeholder=
"Enter username"
/>
</InputGroup>
<InputGroup className=
"mb-"
>
<Input type=
"password"
onChange={
this
.Password} placeholder=
"Enter Password"
/>
</InputGroup>
<Button onClick={
this
.login} color=
"success"
block>Login</Button>
</Form>
</CardBody>
</Card>
</CardGroup>
</Col>
</Row>
</Container>
</div>
);
}
}
export
default
ApiLogin;
Reply
Answers (
1
)
Login with web API in React js
Login authentication core api fetch in react js