I have a select-dropdown-list, it's data is generated from a API/json file. The json resembles the following:
[
{
"id": 444,
"ggg_progid": "0000-111-222-333-44444",
"clientName": "client 1- aaa-bb-01-05 - AA"
}
]
...but I get the error, Unhandled Rejection (SyntaxError): Unexpected end of JSON input, when I run my code using a particular url for the API/json file. So when I copy the code from the API and paste it into myjson.com, then use the url provided by myjson.com, my code works fine.
What could the problem be, both API's have the same json syntax?
Just in case, I provided the code below:
import React, { Component } from 'react';
class Ast extends Component {
constructor(){
super();
this.state = {
data: [],
};
} //end constructor
componentDidMount() {
fetch('http://myapi/:1234/api/clients', {
method: 'GET',
headers: {
'Content-type': 'application/json',
'Authorization': 'Bearer abc123def.abc123def.abc123def'
},
})
.then(results => results.json())
.then(data => this.setState({ data: data }))
}
render() {
console.log(this.state.data);
return (
<div>
<div className="container">
<form>
<h2>Memeber Selection:</h2>
<div>
{
this.state.data.map(item =>(
<div>
<select className="custom-select" id="clientName">>
<option key={item.clientName}>{item.clientName}</option>
</select>
</div>
))
}
</div>
<div>
<button type="submit" className="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
);
}
}
export default Ast
I took the failing URL and pasted it into postman, and it renders results. Any ideal why an error is generated when I use the url in my code?
console.log()-ing the data?