I am using openweather api to create a weather application but my fetch api call is not working. My api call is working in browser but not in my code.
handleSubmit(){
var city = this.state.city;
var url = 'api.apixu.com/v1/current.json?key=67deb752d27d411a9ac101935181007&q=' + city;
console.log(url);
fetch(url, {
method: 'GET',
mode: "no-cors",
headers: { 'Content-Type': 'application/json' }
}).then((res) => {
var resJson = JSON.parse(res);
console.log(resJson);
return resJson;
}).then((resJson) => {
}).catch((err) => {
console.log("error");
});
}
headers: { 'Content-Type': 'application/json' }is utter nonsense (and is actively harmful as it makes the request require a preflight OPTIONS request). Remove it.fetchdo?