hi All,

I'm building a React app, While calling an api inside the app, it give an
error (Unexpected token < in JSON at position 0). In debugger it shows that
the api url redirected to the login page. Where as i'm already logged in
the system, and install the app in the system.
the code is written below.

componentDidMount() {
fetch("http://localhost:8090/dhis/api/25/organisationUnits.json?paging=false
",{
})
.then(response => response.json())
.then(
(result) => {
console.log(result);
this.setState({
isLoaded: true,
orgUnits: result.organisationUnits
});
},
// Note: it's important to handle errors here
// instead of a catch() block so that we don't swallow
// exceptions from actual bugs in components.
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
}
 if i use authorisation in header, then it works fine.
Please help me out.

Thanks
*Shubham Goyal*
Intern, HISP India <https://www.hispindia.org/>
+917508239154 *|* ishubha...@gmail.com
_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp

Reply via email to